如何修复“ urllib.error.HTTPError:HTTP错误404:未找到”

时间:2019-01-16 02:38:30

标签: python

接下来是代码:

import urllib
url=r'http://yann.lecun.com/exdb/mnist\train-images-idx3-ubyte.gz'
urllib.request.urlretrieve(url,'demo.zip')

接下来是错误:

HTTPError                                 Traceback (most recent call last)
<ipython-input-3-a702ad6c8455> in <module>()
      1 import urllib
      2 url=r'http://yann.lecun.com/exdb/mnist\train-images-idx3-ubyte.gz'
----> 3 urllib.request.urlretrieve(url,'demo.zip')

c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
    246     url_type, path = splittype(url)
    247 
--> 248     with contextlib.closing(urlopen(url, data)) as fp:
    249         headers = fp.info()
    250 

    221     else:
    222         opener = _opener
--> 223     return opener.open(url, data, timeout)
    224 
    225 def install_opener(opener):
    530         for processor in self.process_response.get(protocol, []):
    531             meth = getattr(processor, meth_name)
--> 532             response = meth(req, response)
    533 
    534         return response

    640         if not (200 <= code < 300):
    641             response = self.parent.error(
--> 642                 'http', request, response, code, msg, hdrs)
    643 
    644         return response

c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\urllib\request.py in error(self, proto, *args)
    562             http_err = 0
    563         args = (dict, proto, meth_name) + args
--> 564         result = self._call_chain(*args)
    565         if result:
    566             return result

c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
    502         for handler in handlers:
    503             func = getattr(handler, meth_name)
--> 504             result = func(*args)
    505             if result is not None:
    506                 return result

HTTPError: HTTP Error 404: Not Found

如此糟糕的请求,你能帮我吗.. 此错误不是针对代码的。我想到了我的浏览器或urllib模块错误。

1 个答案:

答案 0 :(得分:0)

网址应为:

http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz

mnist后有一个反斜杠,导致将其解释为制表符。