使用Python的代理库请求库发送HTTPS发布请求时出错

时间:2014-06-30 01:52:48

标签: python python-requests

我在发送HTTPS帖子请求时遇到了一个非常奇怪的错误,我发现了一些类似的报告,但我还没有找到解决方案。如果您有任何建议,我们将不胜感激!

Traceback (most recent call last):
  File "C:/Data/Python Projects/Experement.py", line 14, in send_request
    return requests.post(URL + '/verify', proxies=proxy).json()
  File "C:\Python27\lib\site-packages\requests\api.py", line 88, in post
    return request('post', url, data=data, **kwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 456, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 559, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 327, in send
    timeout=timeout
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 488, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 222, in _get_conn
    return conn or self._new_conn()
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 683, in _new_conn
    return self._prepare_conn(conn)
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 647, in _prepare_conn
    conn.connect()
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connection.py", line 179, in connect
    self._tunnel()
  File "c:\Python27\Lib\httplib.py", line 759, in _tunnel
    line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)

2 个答案:

答案 0 :(得分:2)

这似乎是httplib中的一个漏洞:http://bugs.python.org/issue17849。该问题附有一个简短的补丁,因此您可以将其应用于httplib.py的副本。

我快速浏览了urllib3的urllib3和Requests副本中connection.py的提交历史记录,但似乎没有应用任何解决方法。

答案 1 :(得分:1)

您将在这里看到

line = response.fp.readline(_MAXLINE + 1)
TypeError: readline() takes exactly 1 argument (2 given)

请求的函数readline不接受“ self”以外的参数。因此,这确实是一个库错误。

在本讨论的结尾:https://github.com/requests/requests/issues/2159,表明这可能是触发错误的代理配置错误,而且该错误已在python 2.7上修复,如您在此处看到的:https://bugs.python.org/issue17849

也许您可以考虑升级到python3,并请求库。