| 導航:起始頁 > Dive Into Python > SOAP Web 服務 > SOAP 網絡服務故障排除 | << >> | ||||
深入 Python :Dive Into Python 中文版Python 從新手到專家 [Dip_5.4b_CPyUG_Release] |
|||||
是的,SOAP 網絡服務的世界中也不總是歡樂和陽光。有時候也會有故障。
正如你在本章中看到的,SOAP 牽扯了很多層面。SOAP 向 HTTP 服務器發送 XML 文檔并接收返回的 XML 文檔時需要用到 HTTP 層。這樣一來,你在 第 11 章 HTTP Web 服務 學到的調試技術在這里都有了用武之地。你可以 import httplib 并設置 httplib.HTTPConnection.debuglevel = 1 來查看潛在的 HTTP 傳輸。
在 HTTP 層之上,還有幾個可能發生問題的地方。SOAPpy 隱藏 SOAP 語法的本領令你驚嘆不已,但也意味著在發生問題時更難確定問題所在。
下面的這些例子是我在使用 SOAP 網絡服務時犯過的一些常見錯誤以及所產生的錯誤信息。
>>> from SOAPpy import SOAPProxy >>> url = 'http://services.xmethods.net:80/soap/servlet/rpcrouter' >>> server = SOAPProxy(url)>>> server.getTemp('27502')
<Fault SOAP-ENV:Server.BadTargetObjectURI: Unable to determine object id from call: is the method element namespaced?> Traceback (most recent call last): File "<stdin>", line 1, in ? File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 453, in __call__ return self.__r_call(*args, **kw) File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 475, in __r_call self.__hd, self.__ma) File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 389, in __call raise p SOAPpy.Types.faultType: <Fault SOAP-ENV:Server.BadTargetObjectURI: Unable to determine object id from call: is the method element namespaced?>
錯誤配置 SOAP 服務的基本元素是 WSDL 著眼解決的問題。WSDL 文件包含服務 URL 和命名空間,所以你應該不會在這里犯錯。但是,還有其他可能出錯的地方。
>>> wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl' >>> server = WSDL.Proxy(wsdlFile) >>> temperature = server.getTemp(27502)<Fault SOAP-ENV:Server: Exception while handling service request: services.temperature.TempService.getTemp(int) -- no signature match>
Traceback (most recent call last): File "<stdin>", line 1, in ? File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 453, in __call__ return self.__r_call(*args, **kw) File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 475, in __r_call self.__hd, self.__ma) File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 389, in __call raise p SOAPpy.Types.faultType: <Fault SOAP-ENV:Server: Exception while handling service request: services.temperature.TempService.getTemp(int) -- no signature match>
Python 所期待的返回值個數與遠程函數的實際返回值個數不同是另一種可能的錯誤。
>>> wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl' >>> server = WSDL.Proxy(wsdlFile) >>> (city, temperature) = server.getTemp(27502)Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: unpack non-sequence
那么 Google 網絡服務方面又如何呢?我曾經犯過的最常見的錯誤是忘記正確設置應用許可證。
>>> from SOAPpy import WSDL >>> server = WSDL.Proxy(r'/path/to/local/GoogleSearch.wsdl') >>> results = server.doGoogleSearch('foo', 'mark', 0, 10, False, "",... False, "", "utf-8", "utf-8") <Fault SOAP-ENV:Server:
Exception from service object: Invalid authorization key: foo: <SOAPpy.Types.structType detail at 14164616>: {'stackTrace': 'com.google.soap.search.GoogleSearchFault: Invalid authorization key: foo at com.google.soap.search.QueryLimits.lookUpAndLoadFromINSIfNeedBe( QueryLimits.java:220) at com.google.soap.search.QueryLimits.validateKey(QueryLimits.java:127) at com.google.soap.search.GoogleSearchService.doPublicMethodChecks( GoogleSearchService.java:825) at com.google.soap.search.GoogleSearchService.doGoogleSearch( GoogleSearchService.java:121) at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.soap.server.RPCRouter.invoke(RPCRouter.java:146) at org.apache.soap.providers.RPCJavaProvider.invoke( RPCJavaProvider.java:129) at org.apache.soap.server.http.RPCRouterServlet.doPost( RPCRouterServlet.java:288) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.google.gse.HttpConnection.runServlet(HttpConnection.java:237) at com.google.gse.HttpConnection.run(HttpConnection.java:195) at com.google.gse.DispatchQueue$WorkerThread.run(DispatchQueue.java:201) Caused by: com.google.soap.search.UserKeyInvalidException: Key was of wrong size. at com.google.soap.search.UserKey.<init>(UserKey.java:59) at com.google.soap.search.QueryLimits.lookUpAndLoadFromINSIfNeedBe( QueryLimits.java:217) ... 14 more '}> Traceback (most recent call last): File "<stdin>", line 1, in ? File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 453, in __call__ return self.__r_call(*args, **kw) File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 475, in __r_call self.__hd, self.__ma) File "c:\python23\Lib\site-packages\SOAPpy\Client.py", line 389, in __call raise p SOAPpy.Types.faultType: <Fault SOAP-ENV:Server: Exception from service object: Invalid authorization key: foo: <SOAPpy.Types.structType detail at 14164616>: {'stackTrace': 'com.google.soap.search.GoogleSearchFault: Invalid authorization key: foo at com.google.soap.search.QueryLimits.lookUpAndLoadFromINSIfNeedBe( QueryLimits.java:220) at com.google.soap.search.QueryLimits.validateKey(QueryLimits.java:127) at com.google.soap.search.GoogleSearchService.doPublicMethodChecks( GoogleSearchService.java:825) at com.google.soap.search.GoogleSearchService.doGoogleSearch( GoogleSearchService.java:121) at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.soap.server.RPCRouter.invoke(RPCRouter.java:146) at org.apache.soap.providers.RPCJavaProvider.invoke( RPCJavaProvider.java:129) at org.apache.soap.server.http.RPCRouterServlet.doPost( RPCRouterServlet.java:288) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at com.google.gse.HttpConnection.runServlet(HttpConnection.java:237) at com.google.gse.HttpConnection.run(HttpConnection.java:195) at com.google.gse.DispatchQueue$WorkerThread.run(DispatchQueue.java:201) Caused by: com.google.soap.search.UserKeyInvalidException: Key was of wrong size. at com.google.soap.search.UserKey.<init>(UserKey.java:59) at com.google.soap.search.QueryLimits.lookUpAndLoadFromINSIfNeedBe( QueryLimits.java:217) ... 14 more '}>
<< 搜索 Google |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
小結 >> |