简体   繁体   English

TypeError:getresponse()得到一个意外的关键字参数'buffering'

[英]TypeError: getresponse() got an unexpected keyword argument 'buffering'

Cannot Upload from a Windows 7 32 bit OS. 无法从Windows 7 32位操作系统上传。 It works fine on Windows 7 64 bit OS with 32/64 bit Python. 它在带有32/64位Python的Windows 7 64位操作系统上运行良好。 I am using Python 3.4.3 with latest requests API. 我正在使用Python 3.4.3和最新的请求API。

The error I get is: 我得到的错误是:

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'

During handling of the above exception, another exception occurred: 在处理上述异常期间,发生了另一个异常:

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

During handling of the above exception, another exception occurred: 在处理上述异常期间,发生了另一个异常:

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))

During handling of the above exception, another exception occurred: 在处理上述异常期间,发生了另一个异常:

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))

The code is 代码是

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)

This code works fine on a Windows7 64 bit OS, but returns the error as described in Windows7 32 bit OS. 此代码在Windows7 64位操作系统上正常工作,但返回错误,如Windows7 32位操作系统中所述。

Also, I can upload small packages using the provided code on a 32 bit Windows 7 OS. 此外,我可以使用32位Windows 7操作系统上提供的代码上传小包。 The only problem is with uploading large packages. 唯一的问题是上传大包。

Ignore the first ("buffering=True") exception. 忽略第一个(“buffering = True”)异常。 That's an internal backward compatibility artefact. 这是一个内部向后兼容的人工制品。 The real errors are the ones that follow. 真正的错误是随后的错误。

Here's a little more context for @fche's correct answer . 这是@ fche正确答案的更多背景。

This comment from a Requests maintainer sums up what is going on here. 来自Requests维护者的评论总结了这里发生的事情。

This is an unforeseen problem to do with how exception tracebacks are being reported in Python 3. PEP 3134 introduced this 'chaining exceptions' reporting [...]. 这是一个无法预料的问题,如何在Python 3中报告异常回溯.PEP 3134引入了这种“链接异常”报告[...]。 The purpose of this error reporting is to highlight that some exceptions occur in except blocks, and to work out what chain of exceptions was hit. 此错误报告的目的是强调除了块之外会发生一些异常,并确定触发了哪些异常链。 This is potentially very useful: for instance, you can hit an exception after destroying a resource and then attempt to use that resource in the except block, which hits another exception. 这可能非常有用:例如,您可以在销毁资源后点击异常,然后尝试在except块中使用该资源,该资源会遇到另一个异常。 It's helpful to be able to see both exceptions at once. 能够一次看到两个例外是有帮助的。

The key is that the TypeError raised as the first exception is unrelated to the subsequent ones. 关键是作为第一个异常引发的TypeError与后续异常无关。 In fact, that's the standard control flow in urllib3. 实际上,这是urllib3中的标准控制流程。 This means that the real exception that's being raised here is the request.exceptions.ConnectionError exception that wraps the urllib3.exceptions.MaxRetryError exception being raised in urllib3. 这意味着此处引发的真正异常是request.exceptions.ConnectionError异常,该异常包装在urllib3中引发的urllib3.exceptions.MaxRetryError异常。

This is not a Requests bug, it's just an ugly traceback introduced by Python 3. We can try to reduce the nastiness of it somewhat by refactoring the method in urllib3 [...], but that'll only remove the TypeError from the chain: the rest will stay in place. 这不是一个Requests错误,它只是Python 3引入的一个丑陋的回溯。我们可以尝试通过重构urllib3中的方法来减少它的肮脏,但这只会从链中删除TypeError :其余的将留在原地。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:open()获得了意外的关键字参数“缓冲” - TypeError: open() got an unexpected keyword argument 'buffering' 类型错误:contact() 得到了意外的关键字参数“name” - TypeError: contact() got an unexpected keyword argument 'name' TypeError at '' __init__() 得到一个意外的关键字参数 '' - TypeError at '' __init__() got an unexpected keyword argument '' TypeError:backward()得到了一个意外的关键字参数“变量” - TypeError: backward() got an unexpected keyword argument 'variables' 类型错误:__init__() 得到了一个意外的关键字参数“接收者” - TypeError: __init__() got an unexpected keyword argument 'recepient' 类型错误:init() 得到了一个意外的关键字参数“n_iter” - TypeError: init() got an unexpected keyword argument 'n_iter' Python错误“ TypeError:得到了意外的关键字参数'attachmentId'” - Python Error “TypeError: Got an unexpected keyword argument 'attachmentId'” 类型错误:_deserialize() 在棉花糖中有一个意外的关键字参数“部分” - TypeError: _deserialize() got an unexpected keyword argument 'partial' in marshmallow TypeError: f1_score() 得到了一个意外的关键字参数 'average' - TypeError: f1_score() got an unexpected keyword argument 'average' TypeError:__ init __()得到了一个意外的关键字参数'__no_builder'Kivy - TypeError: __init__() got an unexpected keyword argument '__no_builder' Kivy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM