Closed colindean closed 2 years ago
Workaround: get the FontAwesome package from GitHub instead.
https://github.com/FortAwesome/Font-Awesome/releases/download/5.15.4/fontawesome-free-5.15.4-web.zip
I think this is still worth trying to add some more debugging information to or at least trying to figure out if the dependency on urllib is problematic when retrieving from Cloudflare-backed URLs.
Interesting, thanks for the detailed report. I've played with it a little bit, and it seems like the key detail is that the User-Agent header has to be set. Here's a minimized repro:
from urllib.request import Request, urlopen
url = "https://use.fontawesome.com/releases/v5.15.4/fontawesome-free-5.15.4-web.zip"
req = Request(url)
# Even with an empty string as the User-Agent header, the request succeeds. But
# if we remove this line, the request fails with error 403.
req.add_header("user-agent", "")
urlopen(req)
@colindean can you confirm this behavior?
I guess it's reasonable that Peru should set something for the UA. Any proposals for what that should be? @olson-sean-k?
Confirmed.
I'd suggest this:
urllib3 uses python-urllib3/{__version__}
as its UA, so perhaps it's appropriate for Peru to use
f"peru/{peru_version} python-urllib/{urllib.request.__version__}"
If you look at the source for urllib.request
, there are seemingly other ways to create requests that already have the Python default UA but I think the above meets the minimum requirement.
I put up #219 with a stab at a quick fix. It adds the header, at least. I didn't actually test it with my config example above, though, yet.
I tested #219 with the example config and it works! It will fix the problem.
Thanks for finding (and fixing) this, @colindean!
I guess it's reasonable that Peru should set something for the UA. Any proposals for what that should be?
urllib3 uses
python-urllib3/{__version__}
as its UA, so perhaps it's appropriate for Peru to use ...
I'm not too sure, but I think there are three reasonable options:
urllib
use by default (e.g., python-urllib3/{__version__}
).peru/{__version__}
).FWIW, I think I'd lean a bit toward the first option, but I don't have a strong opinion about it.
I'm trying to import fontawesome to a project using Peru 1.3.0.
But it errors:
I think it's a urllib problem:
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…?