Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何简单地从python下载HTTP文件_Python 3.x_Wget_Urllib - Fatal编程技术网

Python 3.x 如何简单地从python下载HTTP文件

Python 3.x 如何简单地从python下载HTTP文件,python-3.x,wget,urllib,Python 3.x,Wget,Urllib,我正在尝试使用urllib.request,但出现以下错误: >>> from urllib.request import urlopen >>> urlopen(url, timeout=5) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.4/urllib/request.py", li

我正在尝试使用
urllib.request
,但出现以下错误:

>>> from urllib.request import urlopen
>>> urlopen(url, timeout=5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/urllib/request.py", line 161, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.4/urllib/request.py", line 469, in open
    response = meth(req, response)
  File "/usr/lib/python3.4/urllib/request.py", line 579, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.4/urllib/request.py", line 507, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 441, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 587, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 504: Gateway Time-out
它就像一个符咒。但是,我不想使用它,因为我的应用程序必须是独立于平台的


有什么想法吗?

值得一看这些方法是否有效。尝试使用
--debug
标志运行
wget
。您将看到标题和发生的任何重定向,这应该是您的请求应该是什么样子的提示。谢谢。似乎我的url包含类似于
084/001/./../084/001/001282.html的内容。如果我规范化这条路径,它就会工作。
os.system('wget %s' % url)