python urllib.request.urlopen不遵循重定向

时间:2013-03-19 13:42:38

标签: 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, 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 个答案:

答案 0 :(得分:1)

看起来,Python版本3.2.0到3.2.2中存在一个错误。

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

Theres相应的错误报告:http://bugs.python.org/issue13696