无法从Windows 7 32位操作系统上传。它在带有32/64位Python的Windows 7 64位操作系统上运行良好。我正在使用Python 3.4.3和最新的请求API。
我得到的错误是:
Traceback (most recent call last): File
"C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 376, in _make_request
httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last): File
"C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
body=body, headers=headers) File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 378, in _make_request
httplib_response = conn.getresponse() File "C:\Python34\lib\http\client.py", line 1171, in getresponse
response.begin() File "C:\Python34\lib\http\client.py", line 351, in begin
version, status, reason = self._read_status() File "C:\Python34\lib\http\client.py", line 313, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "C:\Python34\lib\socket.py", line 374, in readinto
return self._sock.recv_into(b)
ConnectionResetError: WinError 10054] An existing connection was forcibly close d by the remote host
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last): File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
timeout=timeout File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 609, in urlopen
_stacktrace=sys.exc_info()[2]) File "C:\Python34\lib\site-packages\requests\packages\urllib3\util\retry.py", line 245, in increment
raise six.reraise(type(error), error, _stacktrace) File "C:\Python34\lib\site-packages\requests\packages\urllib3\packages\six.py", line 309, in reraise
raise value.with_traceback(tb) File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 559, in urlopen
body=body, headers=headers) File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 378, in _make_request
httplib_response = conn.getresponse() File "C:\Python34\lib\http\client.py", line 1171, in getresponse
response.begin() File "C:\Python34\lib\http\client.py", line 351, in begin
version, status, reason = self._read_status() File "C:\Python34\lib\http\client.py", line 313, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "C:\Python34\lib\socket.py", line 374, in readinto
return self._sock.recv_into(b)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last): File "Upgrader.py", line 12, in
rdst = requests.post(urldst, files={'1_19_0_developer.exe': resp.content}) File "C:\Python34\lib\site-packages\requests\api.py", line 109, in post
return request('post', url, data=data, json=json, *kwargs) File "C:\Python34\lib\site-packages\requests\api.py", line 50, in request
response = session.request(method=method, url=url, *kwargs) File "C:\Python34\lib\site-packages\requests\sessions.py", line 468, in request
resp = self.send(prep, *send_kwargs) File "C:\Python34\lib\site-packages\requests\sessions.py", line 576, in send
r = adapter.send(request, *kwargs) File "C:\Python34\lib\site-packages\requests\adapters.py", line 412, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetErro r(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
代码是
import requests
from requests_file import FileAdapter
s = requests.Session()
s.mount('file://', FileAdapter())
resp = s.get('file:///local_package_name')
urldst = 'Upload URL'
rdst = requests.post(urldst, files={'filename': resp.content})
print(rdst)
此代码在Windows7 64位操作系统上运行正常,但会返回错误,如Windows7 32位操作系统中所述。
此外,我可以使用32位Windows 7操作系统上提供的代码上传小包。唯一的问题是上传大包。
答案 0 :(得分:7)
忽略第一个("缓冲= True")异常。这是一个内部向后兼容性的人工制品。真正的错误就是随之而来的。
答案 1 :(得分:2)
这里是@fche's correct answer的更多内容。
来自请求维护者的This comment总结了这里发生的事情。
这是在Python 3中如何报告异常回溯的不可预见的问题。PEP 3134引入了此“链接异常”报告[...]。此错误报告的目的是突出显示某些异常在除了块中发生,并找出发生了什么异常链。这可能非常有用:例如,您可以在销毁资源后命中异常,然后尝试在except块中使用该资源,这会命中另一个异常。能够一次看到两个例外很有帮助。
关键是作为第一个异常引发的TypeError与后续异常无关。实际上,这就是urllib3中的标准控制流。这意味着这里引发的真正异常是request.exceptions.ConnectionError异常,该异常包装了urllib3中引发的urllib3.exceptions.MaxRetryError异常。
这不是Requests的错误,它只是Python 3引入的一个丑陋的回溯。我们可以通过重构urllib3 [...]中的方法来尝试减轻它的麻烦,但这只会删除TypeError从链中:其余的将留在原处。