Add user agent header for fetch latest commit

For some reason GitLab (or CloudFlare) respond with 403 Forbidden for
requests made using urllib. By setting the user agent we can complete
the requests successfully.

See https://gitlab.com/gitlab-org/gitlab/-/issues/219669 for the
corresponding issue in the GitLab issue tracker.
This commit is contained in:
Robert Helgesson 2020-07-03 23:31:19 +02:00
parent 1444f0ba22
commit e0128b42cf
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -13,9 +13,10 @@ from .manifest import LockedVersion, Repo, RepoType
def fetch_commit_from_feed(url: str) -> str:
req = urllib.request.urlopen(url)
req = urllib.request.Request(url, headers={"User-Agent": "nur-updater"})
res = urllib.request.urlopen(req)
try:
xml = req.read()
xml = res.read()
root = ET.fromstring(xml)
ns = "{http://www.w3.org/2005/Atom}"
xpath = f"./{ns}entry/{ns}link"