summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2022-04-06 15:59:20 +0200
committerGitHub <noreply@github.com>2022-04-06 15:59:20 +0200
commitbeff697cc04290cb80aa7558aac6e0af81cfd5a8 (patch)
tree9f89c1ee62f45a2486ff8ebddb66bd8aa56d5bc1 /lib
parent0dc3c85a909ec722084b72457ae97f972059166e (diff)
downloadspack-beff697cc04290cb80aa7558aac6e0af81cfd5a8.tar.gz
spack-beff697cc04290cb80aa7558aac6e0af81cfd5a8.tar.bz2
spack-beff697cc04290cb80aa7558aac6e0af81cfd5a8.tar.xz
spack-beff697cc04290cb80aa7558aac6e0af81cfd5a8.zip
web.py: set User-Agent (#29919)
Some servers require `User-Agent` to be set, and otherwise error with access denied. One such example is mpich. To fix this, set `User-Agent: Spackbot/[version]` as a header. Apparently by convention, it should include the word `bot`.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/util/web.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/spack/spack/util/web.py b/lib/spack/spack/util/web.py
index dc1a7c24f6..6896c308cf 100644
--- a/lib/spack/spack/util/web.py
+++ b/lib/spack/spack/util/web.py
@@ -24,6 +24,7 @@ import llnl.util.lang
import llnl.util.tty as tty
from llnl.util.filesystem import mkdirp, rename
+import spack
import spack.config
import spack.error
import spack.url
@@ -34,6 +35,9 @@ import spack.util.url as url_util
from spack.util.compression import ALLOWED_ARCHIVE_TYPES
from spack.util.path import convert_to_posix_path
+#: User-Agent used in Request objects
+SPACK_USER_AGENT = "Spackbot/{0}".format(spack.spack_version)
+
if sys.version_info < (3, 0):
# Python 2 had these in the HTMLParser package.
from HTMLParser import HTMLParseError, HTMLParser # novm
@@ -116,7 +120,7 @@ def read_from_url(url, accept_content_type=None):
url = url_util.format(url)
if sys.platform == "win32" and url_scheme == "file":
url = convert_to_posix_path(url)
- req = Request(url)
+ req = Request(url, headers={'User-Agent': SPACK_USER_AGENT})
content_type = None
is_web_url = url_scheme in ('http', 'https')