[英]unexpected keyword argument 'buffering' - python client
我收到錯誤,因為“getresponse()得到了一個意外的關鍵字參數'緩沖'”。 完整的錯誤日志是:
[INFO ] Kivy v1.8.0
[INFO ] [Logger ] Record log in C:\Users\Sudheer\.kivy\logs\kivy_14-08-15_21.txt
[INFO ] [Factory ] 157 symbols loaded
[DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG ] [Cache ] register <kv.image> with limit=None, timeout=60s
[DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout=Nones
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil ignored)
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600s
[DEBUG ] [App ] Loading kv <D:\OS Files\workspace\Assistant\start.kv>
[INFO ] [Text ] Provider: pygame
[DEBUG ] [Cache ] register <kv.loader> with limit=500, timeout=60s
[INFO ] [Loader ] using a thread pool of 2 workers
[DEBUG ] [Cache ] register <textinput.label> with limit=None, timeout=60.0s
[DEBUG ] [Cache ] register <textinput.width> with limit=None, timeout=60.0s
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG ] [Window ] Display driver windib
[DEBUG ] [Window ] Actual window size: 800x600
[DEBUG ] [Window ] Actual color bits r8 g8 b8 a0
[DEBUG ] [Window ] Actual depth bits: 24
[DEBUG ] [Window ] Actual stencil bits: 8
[DEBUG ] [Window ] Actual multisampling samples: 2
GLEW initialization succeeded
[INFO ] [GL ] OpenGL version <b'3.3.0'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'GeForce 9400 GT/PCIe/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 3, 3
[INFO ] [GL ] Shading version <b'3.30 NVIDIA via Cg compiler'>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <32>
[DEBUG ] [Shader ] Fragment compiled successfully
[DEBUG ] [Shader ] Vertex compiled successfully
[DEBUG ] [ImagePygame ] Load <C:\Kivy180\kivy\kivy\data\glsl\default.png>
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[DEBUG ] [Atlas ] Load <C:\Kivy180\kivy\kivy\data\..\data\images\defaulttheme.atlas>
[DEBUG ] [Atlas ] Need to load 1 images
[DEBUG ] [Atlas ] Load <C:\Kivy180\kivy\kivy\data\..\data\images\defaulttheme-0.png>
[DEBUG ] [ImagePygame ] Load <C:\Kivy180\kivy\kivy\data\..\data\images\defaulttheme-0.png>
[INFO ] [GL ] NPOT texture support is available
[INFO ] [OSC ] using <thread> for socket
[DEBUG ] [Base ] Create provider from mouse
[DEBUG ] [Base ] Create provider from wm_touch
[DEBUG ] [Base ] Create provider from wm_pen
[INFO ] [Base ] Start application main loop
{'DoWorkResult': 'Working'}
http://localhost:9624/BasicServ.svc/auth/Authorize/admin/1234
[INFO ] [Base ] Leaving application in progress...
Traceback (most recent call last):
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\packages\urllib3\connectionpool.py", line 313, 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:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\packages\urllib3\connectionpool.py", line 480, in urlopen
body=body, headers=headers)
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\packages\urllib3\connectionpool.py", line 315, in _make_request
httplib_response = conn.getresponse()
File "C:\Kivy180\Python33\lib\http\client.py", line 1147, in getresponse
response.begin()
File "C:\Kivy180\Python33\lib\http\client.py", line 358, in begin
version, status, reason = self._read_status()
File "C:\Kivy180\Python33\lib\http\client.py", line 320, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Kivy180\Python33\lib\socket.py", line 297, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\adapters.py", line 330, in send
timeout=timeout
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\packages\urllib3\connectionpool.py", line 530, in urlopen
raise MaxRetryError(self, url, e)
requests.packages.urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9624): Max retries exceeded with url: /BasicServ.svc/auth/Authorize/admin/1234 (Caused by <class 'ConnectionResetError'>: [WinError 10054] An existing connection was forcibly closed by the remote host)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\OS Files\workspace\Assistant\main.py", line 10, in <module>
StartApp().run()
File "C:\Kivy180\kivy\kivy\app.py", line 792, in run
runTouchApp()
File "C:\Kivy180\kivy\kivy\base.py", line 481, in runTouchApp
EventLoop.window.mainloop()
File "C:\Kivy180\kivy\kivy\core\window\window_pygame.py", line 381, in mainloop
self._mainloop()
File "C:\Kivy180\kivy\kivy\core\window\window_pygame.py", line 287, in _mainloop
EventLoop.idle()
File "C:\Kivy180\kivy\kivy\base.py", line 324, in idle
self.dispatch_input()
File "C:\Kivy180\kivy\kivy\base.py", line 309, in dispatch_input
post_dispatch_input(*pop(0))
File "C:\Kivy180\kivy\kivy\base.py", line 220, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:4537)
return handler(*largs)
File "C:\Kivy180\kivy\kivy\core\window\__init__.py", line 645, in on_motion
self.dispatch('on_touch_down', me)
File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:4537)
return handler(*largs)
File "C:\Kivy180\kivy\kivy\core\window\__init__.py", line 657, in on_touch_down
if w.dispatch('on_touch_down', touch):
File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:4537)
return handler(*largs)
File "C:\Kivy180\kivy\kivy\uix\widget.py", line 284, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:4537)
return handler(*largs)
File "C:\Kivy180\kivy\kivy\uix\widget.py", line 284, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:4537)
return handler(*largs)
File "C:\Kivy180\kivy\kivy\uix\behaviors.py", line 93, in on_touch_down
self.dispatch('on_press')
File "_event.pyx", line 312, in kivy._event.EventDispatcher.dispatch (kivy\_event.c:4491)
if handler(self, *largs):
File "C:\Kivy180\kivy\kivy\lang.py", line 1299, in custom_callback
exec(__kvlang__.co_value, idmap)
File "D:\OS Files\workspace\Assistant\start.kv", line 65, in <module>
on_press: root.Authorization(self,userid.text,password.text)
File "D:\OS Files\workspace\Assistant\forms.py", line 18, in Authorization
if self.loginclass.Authorization()== True:
File "D:\OS Files\workspace\Assistant\classes.py", line 8, in Authorization
return LoginAccess(self.userid, self.password)
File "D:\OS Files\workspace\Assistant\dbcodes.py", line 9, in LoginAccess
response = requests.get('http://localhost:9624/BasicServ.svc/auth/Authorize/'+userid+'/'+password,stream=False)
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\api.py", line 55, in get
return request('get', url, **kwargs)
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\sessions.py", line 383, in request
resp = self.send(prep, **send_kwargs)
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\sessions.py", line 486, in send
r = adapter.send(request, **kwargs)
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\adapters.py", line 378, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9624): Max retries exceeded with url: /BasicServ.svc/auth/Authorize/admin/1234 (Caused by <class 'ConnectionResetError'>: [WinError 10054] An existing connection was forcibly closed by the remote host)
我的相關wcf服務代碼是:
<OperationContract()>
<WebGet(UriTemplate:="Authorize/{id}/{pw}", BodyStyle:=WebMessageBodyStyle.Wrapped, RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json)>
Function Authorize(ByVal id As String, ByVal pw As String)
Function Authorize(ByVal id As String, ByVal pw As String) Implements IBasicServ.Authorize
Dim c As New List(Of Guid)
For i = 0 To 10
c.Add(Guid.NewGuid)
Next
Return c
End Function
python客戶端中的代碼是:
import requests
import json
def LoginAccess(userid, password):
response = requests.get('http://localhost:9624/BasicServ.svc/auth/test/')
print (response.json())
print('http://localhost:9624/BasicServ.svc/auth/Authorize/'+userid+'/'+password)
response = requests.get('http://localhost:9624/BasicServ.svc/auth/Authorize/'+userid+'/'+password,stream=False)
print (response.json())
第一個響應是僅用於測試服務,它正在工作,第二個響應我收到錯誤。 我會適當地編碼加密和SSL,但目前正試圖讓其他客戶端工作。 我還測試了Stream = True和False,但結果是一樣的。
我用Google搜索並發現錯誤通常與請求模塊舊版有關,但我使用的是更新版本。
請求模塊是2.2.1 Python 3.3,在.net 4上使用Kivy WCF
編輯:WCF Web配置文件:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServBehav" name="AssistantWcf.BasicServ">
<endpoint address="auth" behaviorConfiguration="EndBehav" binding="webHttpBinding" name="endpointname" contract="AssistantWcf.IBasicServ" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="EndBehav">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServBehav">
<!-- To avoid disclosing metadata information, set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" httpGetBindingConfiguration="" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
您似乎對Python 3不熟悉。它引入了一種新的回溯方式,以便您可以最好地確定代碼中的哪條路徑,以便您可以找到最終異常的來源。 讓我們來看看你的追溯:
Traceback (most recent call last):
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\packages\urllib3\connectionpool.py", line 313, 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:
這里最重要的是最后一行: “在處理上述異常時,發生了另一個異常:” 。 這表明TypeError: getresponse() got an unexpected keyword argument 'buffering'
不是停止你的程序的異常的來源,但它實際上是在發生不同的異常時被處理的。
您現在會注意到“在處理上述異常時,發生了另一個異常:”在您粘貼的輸出中再出現幾次,最終跟蹤結束於:
File "C:\Kivy180\Python33\lib\site-packages\requests-2.2.1-py3.3.egg\requests\adapters.py", line 378, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9624): Max retries exceeded with url:
/BasicServ.svc/auth/Authorize/admin/1234
(Caused by <class 'ConnectionResetError'>:
[WinError 10054] An existing connection was forcibly closed by the remote host)
我已經將最后一行分解為更具可讀性(因此它不會滾動到一邊)。 您看到的異常是由服務器強行關閉已打開的連接引起的。 如果您使用的是Session
對象,我通常希望看到這個,因為默認情況下會為您執行連接池,但是您每次都使用創建新Session
對象的功能API。 這意味着如果這種情況反復發生,這里的服務器很可能行為不端。 服務器拒絕響應您的請求並強行關閉已建立的連接。 在嘗試讀取響應時,urllib3接收到WinError
異常,除了提供它自己的異常ConnectionResetError
之外,沒有其他方法可以恢復。 請求然后捕獲它並引發它自己的ConnectionError
。
這里的問題似乎不是請求,而是一個行為不端的服務器。
另外,在URL中使用用戶名和密碼是一個非常糟糕的主意。 我建議調查使用HTTP摘要式身份驗證,HTTP基本身份驗證或實現更安全的東西(如基於令牌的身份驗證方案)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.