python urllib.request.urlopen不';不要跟随重定向

python urllib.request.urlopen不';不要跟随重定向,python,redirect,urllib,Python,Redirect,Urllib,我正在使用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

我正在使用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
回溯(最近一次呼叫最后一次):
文件“solver.py”,第93行,在
生成元数据(“巴别塔”)
generateMetadata中第76行的文件“solver.py”
linklist=parseURL(名称)
parseURL中的文件“solver.py”,第20行
resp=opener.open(REP_URL+name+'/'))
文件“/usr/lib/python3.2/urllib/request.py”,第375行,打开
响应=方法(请求,响应)
http_响应中的文件“/usr/lib/python3.2/urllib/request.py”,第487行
“http”、请求、响应、代码、消息、hdrs)
文件“/usr/lib/python3.2/urllib/request.py”,第407行出错
结果=自身调用链(*args)
文件“/usr/lib/python3.2/urllib/request.py”,第347行,在调用链中
结果=func(*args)
http\u error\u 302中的文件“/usr/lib/python3.2/urllib/request.py”,第560行
标题(fp)
urllib.error.HTTPError:HTTP错误301:已永久移动-不允许重定向到url'/simple/Babel'

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

看起来,Python版本3.2.0到3.2.2中有一个bug

如果你知道你的程序的用户将使用这个版本,你可以尝试猴子补丁。(如果使用的是故障版本之一,则使用3.2.3中的修补版本覆盖模块)


有相应的错误报告:

我无法用Python 3.2.3重现此错误。在异常之前,如果urlparts.scheme不在('http'、'https'、'ftp'、'')中,则行为
。您的URL必须是不可靠的,请检查它是否使用了正确的方案。我用python 3.2.3和3.3测试了同一行,两个都有效。这不可能是因为我碰到了一个bug,它只存在于我的subversion中,对吗?当你收到这个错误时,你在传递什么URL?查看
repr(url)
以确保捕获任何特殊字符。Hrm,再次查看,我怀疑响应已损坏。您可能希望包含指向我给您的错误报告的链接。