2013-03-19 139 views
0

我正在使用python 3.2.2。如果我尝试做:python urllib.request.urlopen不遵循重定向

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 

搜索我发现,它会自动处理重定向后。

+1

我不能与Python 3.2.3重现此。 – 2013-03-19 13:57:47

+1

就在此之前,异常是'if urlparts.scheme not in'('http','https','ftp',''):'。您的网址必须是狡猾的,请检查它是否使用了正确的方案。 – 2013-03-19 14:04:42

+0

我测试了python 3.2.3和3.3的相同行,并且都工作。这不可能是我碰到了一个只存在于我的颠覆中的bug,可以吗? – WeGi 2013-03-19 14:12:34

回答

1

所以看来,Python版本3.2.0到3.2.2中存在一个bug。

如果你知道你的程序的用户会使用这个版本,你可以尝试猴子补丁。 (如果他们正在使用的故障版本之一,从3.2.3覆盖具有修补一个模块)

即使世界相应的错误报告:http://bugs.python.org/issue13696

+0

您可能希望包含指向我给您的错误报告的链接。 – 2013-03-19 15:01:58