From e0128b42cf0e107f9419146905d2df729ed4d0ca Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Fri, 3 Jul 2020 23:31:19 +0200 Subject: [PATCH] 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. --- nur/prefetch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nur/prefetch.py b/nur/prefetch.py index 4c175c4ed..6d9582085 100644 --- a/nur/prefetch.py +++ b/nur/prefetch.py @@ -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"