question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot download package possibly because of urllib defaults

See original GitHub issue

I’m trying to import fontawesome to a project using Peru 1.3.0.

imports:
  fontawesome: deps/font-awesome

curl module fontawesome:
  url: https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-web.zip
  unpack: zip

But it errors:

$ peru sync
In target "fontawesome":
  Error fetching https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-web.zip
  HTTP Error 403: Forbidden

I think it’s a urllib problem:

from urllib.error import HTTPError
import urllib.request

url = "https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-web.zip"

try:
  req = urllib.request.urlopen(url)
except HTTPError as e:
  print(e.headers)
# this will fail and print something

# this succeeds
import urllib3
http = urllib3.PoolManager()
resp = http.request("GET", "https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-web.zip")
print(resp.status)
# succeeds

The urllib request fails but urllib3 succeeds. I don’t think urllib’s HTTPError gives you access to the request headers, so I can’t really tell what’s wrong here. I’m able to retrieve the file with curl, wget, aria2c, and python via urllib3.

Running peru --verbose sync gave me a stack trace that simply emphasizes “yeah, that’s a 403” and the headers I get back from the request don’t really say what’s wrong. I assume it’s some kind of bot protection on Cloudflare…?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
colindeancommented, Dec 1, 2021

I tested #219 with the example config and it works! It will fix the problem.

0reactions
colindeancommented, Dec 1, 2021

#219 goes with № 3 in that list and pulls the urllib UA directly from a core class that won’t go away. urllib doesn’t — IMO — sufficiently abstract this value 👎

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot import urllib in Python - Stack Overflow
1 Answer 1 · As metioned in the comments, urllib is not installed through pip , it is part of the standard library,...
Read more >
HOWTO Fetch Internet Resources Using The urllib Package ...
Often, URLError is raised because there is no network connection (no route to the specified server), or the specified server doesn't exist. In...
Read more >
Python's urllib.request for HTTP Requests - Real Python
In this tutorial, you'll be making HTTP requests with Python's built-in urllib.request. You'll try out examples and review common errors ...
Read more >
SSL certificate error with pip 21.0.1 · Issue #9568 - GitHub
I have found the root cause of the problem and pip can fix its end. So there are two reasons for this error:...
Read more >
URLLib.Request Errors - Esri Community
pip is the mechanism used to get packages, you should check if you have urllib3 installed by opening the python terminal at your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found