无法使用 SOAPpy 调用 Web 服务方法
我尝试使用 SOAPpy 调用 Web 服务:
from SOAPpy import SOAPProxy
url = 'http://www.webservicex.net/WeatherForecast.asmx'
server = SOAPProxy(url);
print server.GetWeatherByPlaceName('Dallas');
print server.GetWeatherByZipCode ('33126');
服务器调用失败:
Traceback (most recent call last):
File "soap_test.py", line 6, in <module>
print server.GetWeatherByPlaceName('Dallas');
File "C:\usr\bin\Python26\lib\site-packages\SOAPpy\Client.py", line 451, in __call__
return self.__r_call(*args, **kw)
File "C:\usr\bin\Python26\lib\site-packages\SOAPpy\Client.py", line 473, in __r_call
self.__hd, self.__ma)
File "C:\usr\bin\Python26\lib\site-packages\SOAPpy\Client.py", line 387, in __call
raise p
SOAPpy.Types.faultType: <Fault soap:Client: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: GetWeatherByPlaceName.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing): >
我做错了什么?
I am trying to call a webservice using SOAPpy:
from SOAPpy import SOAPProxy
url = 'http://www.webservicex.net/WeatherForecast.asmx'
server = SOAPProxy(url);
print server.GetWeatherByPlaceName('Dallas');
print server.GetWeatherByZipCode ('33126');
The server call fails:
Traceback (most recent call last):
File "soap_test.py", line 6, in <module>
print server.GetWeatherByPlaceName('Dallas');
File "C:\usr\bin\Python26\lib\site-packages\SOAPpy\Client.py", line 451, in __call__
return self.__r_call(*args, **kw)
File "C:\usr\bin\Python26\lib\site-packages\SOAPpy\Client.py", line 473, in __r_call
self.__hd, self.__ma)
File "C:\usr\bin\Python26\lib\site-packages\SOAPpy\Client.py", line 387, in __call
raise p
SOAPpy.Types.faultType: <Fault soap:Client: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: GetWeatherByPlaceName.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing): >
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 .NET Web 服务时,您可以向调用添加肥皂操作覆盖。就像下面这样。确认工作代码。
有人编写了一个 类 来执行类似的操作。
上述 .Net 包装器的修改版本:
When consuming .NET webservices, you can add a soap action override to the call. Like the following. Confirmed working code.
Someone wrote a class to do something similar.
A modified version of the above wrapper for .Net:
正如错误消息所述,SOAPpy 不会添加 SOAPAction HTTP 标头。这就是 SOAPpy 不适用于许多服务的原因。尝试 suds,这是一个有效的示例:
As error message states, SOAPpy doesn't add SOAPAction HTTP header. That's why SOAPpy won't work for many services. Try suds, here is a working example: