[英]python urllib.request.urlopen doesn't follow redirect
我正在使用python 3.2.2。 如果我尝试这样做:
urllib.request.urlopen('https://pypi.python.org/simple/babel')
我收到以下错误消息:
Traceback (most recent call last):
File "solver.py", line 93, in <module>
generateMetadata('babel')
File "solver.py", line 76, in generateMetadata
linklist = parseURL(name)
File "solver.py", line 20, in parseURL
resp = opener.open(REP_URL+name+'/')
File "/usr/lib/python3.2/urllib/request.py", line 375, in open
response = meth(req, response)
File "/usr/lib/python3.2/urllib/request.py", line 487, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.2/urllib/request.py", line 407, in error
result = self._call_chain(*args)
File "/usr/lib/python3.2/urllib/request.py", line 347, in _call_chain
result = func(*args)
File "/usr/lib/python3.2/urllib/request.py", line 560, in http_error_302
headers, fp)
urllib.error.HTTPError: HTTP Error 301: Moved Permanently - Redirection to url '/simple/Babel' is not allowed
搜索后,我发现它应该自动处理重定向。
如此看来,Python版本3.2.0至3.2.2中存在一个错误。
如果您知道程序的用户将使用此版本,则可以尝试使用猴子补丁程序。 (如果他们使用的是故障版本之一,则使用3.2.3中的补丁程序覆盖模块)
有相应的错误报告: http : //bugs.python.org/issue13696
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.