导航: 起始页 > Dive Into Python > SOAP Web 服务 > SOAP 网络服务故障排除 | << >> | ||||
Python 研究(Dive Into Python)Python 从新手到高手 [DIP_5_4_CPUG_RELEASE] |
是的,SOAP 网络服务的世界中也不总是欢乐和阳光。 有时候也会有故障。
正如你在本章中看到的,SOAP 牵扯了很多层面。 需要 HTTP 层,SOAP 需要向 HTTP 服务器发送 XML 文档并接收返回的 XML 文档。这样一来,你在 第 11 章 HTTP Web 服务 学到的差错技术在这里都有了用武之地。你可以 import httplib 并设置 httplib.HTTPConnection.debuglevel = 1 来查看潜在的 HTTP 传输。
在 HTTP 层之上,还有几个可能发生问题的地方。 SOAPpy 隐藏 SOAP 语法的本领令你惊叹不已,但也意味着在发生问题时更难确定问题所在。
下面的这些例子是我在使用 SOAP 网络服务时犯过的一些常见错误以及所产生的错误信息。
例 12.15. 以错误的设置调用 Proxy 方法
>>> 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 和命名空间,所以你应该不会在这里犯错。但是,还有其他可能出错的地方。
例 12.16. 以错误参数调用方法
>>> 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 所期待的返回值个数与远程函数的实际返回值个数不同是另一种可能的错误。
例 12.17. 调用时方法所期待的返回值个数错误
>>> 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 网络服务方面又如何呢?最常见的错误是我曾经犯过的忘记正确设置应用许可证错误。
例 12.18. 调用方法返回一个应用指定错误
>>> 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 '}>
进一步阅读
- New developments for SOAPpy 一步步连接到另一个不名副其实的 SOAP 服务。
<< 搜索 Google |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
小结 >> |