Search code examples
pythonurllib

python: urllib.request.urlopen() HTTP Error 308 Permanent redirect


i was just trying to read a file from the internet.. then an error came..

Traceback (most recent call last):
  File "E:\Sapphire\Programming\download_file.py", line 46, in <module>
    download(arg[1])
  File "E:\Sapphire\Programming\download_file.py", line 19, in download
    file_info = req.urlopen("http://proget.whirlpool.repl.co/{}/{}.txt".format(arch, name))
  File "E:\Programming\Python38-32\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "E:\Programming\Python38-32\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "E:\Programming\Python38-32\lib\urllib\request.py", line 640, in http_response
    response = self.parent.error(
  File "E:\Programming\Python38-32\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "E:\Programming\Python38-32\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "E:\Programming\Python38-32\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 308: Permanent Redirect

the line that brought the error (line 20):

file_info = req.urlopen("http://proget.whirlpool.repl.co/{}/{}.txt".format(arch, name))

(the link that it should use is correct..) any ideas how it came?

SPECS:
OS: Windows 7 SP1
Python: Python 3.8.10
Arch: x86 (32-bit)

Solution

  • Http is outdated, so most sites would redirect to https.

    So use

    file_info = req.urlopen("https://proget.whirlpool.repl.co/{}/{}.txt".format(arch, name))