Python 访问soap服务
2017-05-17 17:31
211 查看
使用库:subs
功能:使用其中的GetData服务获取北京各个地点的空气情况
GetData服务的请求示例:
soap服务信息:
网址:http://mobile.bjmemc.com.cn/AirService/Service.asmx功能:使用其中的GetData服务获取北京各个地点的空气情况
GetData服务的请求示例:
POST /AirService/Service.asmx HTTP/1.1 Host: mobile.bjmemc.com.cn Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/GetData" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <MySoapHeader xmlns="http://tempuri.org/"> <UserName>string</UserName> <PassWord>string</PassWord> </MySoapHeader> </soap:Header> <soap:Body> <GetData xmlns="http://tempuri.org/"> <DevID>string</DevID> <DevType>string</DevType> </GetData> </soap:Body> </soap:Envelope>
Python代码的实现:
# -*- coding:UTF-8 -*- from suds.client import Client def getAirInfo(): url = 'http://mobile.bjmemc.com.cn/AirService/Service.asmx?wsdl' #一般都是网址后面加个?wsdl,你可以打开看一下,是一堆xml文件 client = Client(url) #创建一个客户端 header = client.factory.create('MySoapHeader') #请求头,名字按他给的xml header.UserName = '******' #请求头里的用户名和密码,这是个付费服务 header.PassWord = '******' client.set_options(soapheaders=[header,]) #将封装好的请求头加入到client中 result = client.service.GetData() #调用GetData()服务,获取返回数据,返回一个text文本 print result
相关文章推荐
- WCF跨域 这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP
- 以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务 问题解决
- 从 PHP 脚本中访问企业应用程序 使用 PHP 5 SOAP 扩展访问 WebSphere Web 服务
- iOS开发:使用SOAP访问Web服务
- 尝试向 URI“ ”发出请求时出错。这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务...。出现此错误也可能是由于使用的是 Web 服务代理中的内部类型而没有使用 InternalsVisibleToAttribute 属性。
- Python Web 服务开发者: Python SOAP 库,第 4 部分
- SOAP访问Web服务
- Python Web 服务开发者 第 6 部分: Python SOAP 库,第 2 部分
- 使用SOAP访问web服务
- soap 1.1 访问服务
- BizTalk 发布服务接口后访问该服务出现错误“Internal SOAP process failed”
- WCF跨域 这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP
- 转:WCF跨域 这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP
- 使用SOAP访问Web服务
- 这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP 服务。
- WCF跨域 这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP
- 开始尝试一下soap,用python访问wsdl服务
- WCF跨域 这可能是由于试图以跨域方式访问服务而又没有正确的跨域策略,或策略不适用于 SOAP
- 使用SOAP访问Web服务
- [C# | WinCE | Solution] 在 WinCE 上访问 SSL 加密后的 WCF SOAP 服务接口出现“未能与远程服务器建立信任关系”