From f150ecb58c90b22caa50acb5dcb22aa4f128c98d Mon Sep 17 00:00:00 2001 From: Alexandru Fikl <alexfikl@gmail.com> Date: Thu, 22 Oct 2020 18:42:05 -0500 Subject: [PATCH] add a user agent to seem like less of a bot --- pytools/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pytools/__init__.py b/pytools/__init__.py index 0dc6622..912198f 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -2208,8 +2208,13 @@ def download_from_web_if_not_present(url, local_name=None): local_name = basename(url) if not exists(local_name): - from six.moves.urllib.request import urlopen - with urlopen(url) as inf: + from pytools.version import VERSION_TEXT + from urllib.request import Request, urlopen + req = Request(url, headers={ + "User-Agent": f"pytools/{VERSION_TEXT}" + }) + + with urlopen(req) as inf: contents = inf.read() with open(local_name, "wb") as outf: -- GitLab