环境:
我使用的WSDL(服务器)有以下架构子部分(我试图用纯文本清楚地写出来) -
[第1节]
searchRequest: (searchRequest){
userIdentification = (userIdentification){
username = ""
password = ""
}
itineraryArr = (itineraryArray){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
_arrayType = ""
}
...
...
Run Code Online (Sandbox Code Playgroud)
[第2节]
itinerary: (itinerary){
departurePoint = (locationPoint){
locationId = None
radius = None
}
arrivalPoint = (locationPoint){
locationId = None
radius = None
}
...
...
Run Code Online (Sandbox Code Playgroud)
'userIdentification'没有问题(这是一种"简单"类型)
但是,'itineraryArr'是一个'行程'数组,我不知道如何使用python来创建XML数组.
例如,我尝试了几种组合
itinerary0 = self.client.factory.create('itinerary')
itineraryArray = self.client.factory.create('itineraryArray')
itineraryArray = [itinerary0]
searchRequest.itineraryArr = itineraryArray …Run Code Online (Sandbox Code Playgroud) 请告知图书馆在python中使用soap.
现在,我正在尝试使用"suds",我无法理解如何从服务器回复
代码示例获取http标头:
from suds.client import Client
url = "http://10.1.0.36/money_trans/api3.wsdl"
client = Client(url)
login_res = client.service.Login("login", "password")
Run Code Online (Sandbox Code Playgroud)
变量"login_res"包含xml答案,并且不包含http标头.但我需要从他们那里得到会话ID.
我必须用肥皂水和Python做肥皂请求
<soap:Body>
<registerOrder>
<order merchantOrderNumber="" description="" amount="" currency="" language="" xmlns="">
<returnUrl>http://mysafety.com</returnUrl>
</order>
</registerOrder>
</soap:Body>
Run Code Online (Sandbox Code Playgroud)
如何在registerOrder中添加属性?
我很确定suds并没有像我期望的那样缓存我的WSDL和XSD .以下是我知道没有使用缓存对象的方法:
client = Client(url)我有一个小程序,它创建一个suds客户端,发送一个请求,获取响应,然后结束.我的期望是每次运行程序时,都应该从文件缓存中获取WSDL和XSD文件,而不是从URL中获取.这就是为什么我认为:
client.options.cache.duration 被设置为 ('days', 1)client.options.cache.location设置为c:\docume~1\mlin\locals~1\temp\suds,我看到每次运行程序时生成并重新生成缓存文件我是否误解了suds缓存应该如何工作?
我正在使用一些有点非标准的SOAP Web服务.对webservice的大多数调用都会按预期返回标准SOAP XML,但是一个调用特别会返回一个JSON字符串.这会破坏客户端的xml解析器.
我的问题是; 有没有办法在SUDS中的特定web方法上指定返回类型,以便它不会尝试通过xml解析器运行它?我只想要原始的JSON响应.
我正在尝试使用SUDS,并试图弄清楚为什么我无法使身份验证工作(或https).
我尝试访问的服务是通过https进行基本摘要式身份验证.根据调试,它似乎使用http而不是https.但不确定我错过了什么.任何线索都表示赞赏.
from suds.client import Client
from suds.transport.http import HttpAuthenticated
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
def main():
url = 'https://blah.com/soap/sp/Services?wsdl'
credentials = dict(username='xxxx', password='xxxx')
t = HttpAuthenticated(**credentials)
client = Client(url, location='https://blah.com/soap/sp/Services', transport=t)
print client.last_sent()
if __name__=="__main__":
main()
Run Code Online (Sandbox Code Playgroud)
调试输出:
DEBUG:suds.wsdl:阅读wsdl at:https://blah.com/soap/sp/Services ? wsdl ... DEBUG:suds.transport.http:opening(https://blah.com/soap/sp/服务?wsdl)
snip ...
文件"C:\ Python27\Lib\site-packages\suds-0.4-py2.7\suds\reader.py",第95行,下载
fp = self.options.transport.open (请求(URL))文件"C:\ Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py",第173行,打开
返回HttpTransport.open(self,request)文件"C:\ Python27\Lib\site-packages\suds-0.4-py2.7\suds\transport\http.py",第64行,在open中
引发TransportError(str(e),e.code,e.fp )suds.transport.TransportError:HTTP错误401:需要授权
处理UTF-8时出现常见错误 - "无效令牌"
在我的例子中,它来自处理不尊重unicode字符的SOAP服务提供者,只是将值截断为100字节而忽略了第100个字节可能在多字节字符的中间:例如:
<name xsi:type="xsd:string">??????????????? ?????????????(????\xef\xbc</name>
Run Code Online (Sandbox Code Playgroud)
在截断刀假定世界使用1字节字符之后,最后两个字节是3字节unicode字符的剩余字节.下一站,sax解析器和:
xml.sax._exceptions.SAXParseException: <unknown>:1:2392: not well-formed (invalid token)
Run Code Online (Sandbox Code Playgroud)
我不再关心这个角色了.它应该从文档中删除并允许sax解析器运行.
除了这些值之外,XML回复在其他方面都有效.
问题:如何在不解析整个文档并重新发明UTF-8编码来检查每个字节的情况下如何删除此字符?
使用:Python + SUDS
我正在尝试使用salesforce-python-toolkit对Salesforce API进行Web服务调用,但是我无法让客户端通过代理.由于工具包是基于suds的,我尝试使用suds本身来看看我是否可以让它尊重那里的代理设置,但它也没有用.
这在OS X 10.7(python 2.7)和ubuntu 12.04上的泡沫0.3.9上进行了测试.
我做的一个示例请求最终没有通过代理(只是在本地运行的burp或charles代理):
import suds
ws = suds.client.Client('file://sandbox.xml',proxy={'http':'http://localhost:8888'})
ws.service.login('user','pass')
Run Code Online (Sandbox Code Playgroud)
我用代理尝试了各种各样的东西 - 使用FQDN丢弃http://,使用IP.我已经逐步完成了pdb中的代码并看到它设置了代理选项.我还尝试在没有代理的情况下实例化客户端,然后使用以下命令设置它:ws.set_options(proxy = {'http':'http:// localhost:8888'})
肥皂水不再使用代理吗?我没有看到它直接列在这里http://jortel.fedorapeople.org/suds/doc/suds.options.Options-class.html,但我确实在运输中看到它.我是否需要通过运输设置不同的方式?当我走进pdb时,看起来确实是在使用传输,但我不确定如何.
谢谢!
我有一些来自SOAPAPI的数据Suds,我需要在Python脚本中解析它.在我离开并编写解析器之前(不仅仅是这个要做):
1)有人认识到这是什么吗?它是Suds (文档)返回的标准复杂对象数据类型.应该发现那个.
2)如果是这样,是否有可用于将其转换为Python字典的现有库?如何将此对象解析为Python dict?我似乎可以将字典传递给Suds,但看不到一个简单的方法让一个人退出.
(ArrayOfBalance){
Balance[] =
(Balance){
Amount = 0.0
Currency = "EUR"
},
(Balance){
Amount = 0.0
Currency = "USD"
},
(Balance){
Amount = 0.0
Currency = "GBP"
},
}
Run Code Online (Sandbox Code Playgroud) 我移植过,将其与开发的代码suds 0.6过来zeep 2.4.0.
以前的泡沫代码:
client = Client(WSDLfile, proxy=proxy, faults=True)
config = client.factory.create('perUserDataExportConfiguration')
config.param1 = 'something'
...
data = client.service.exportPerUserData(username,password,config)
Run Code Online (Sandbox Code Playgroud)
密码:
session = requests.Session()
session.verify = False
transport = Transport(session=session)
client = Client(WSDLfile, strict=False, transport=transport)
config = client.type_factory('ns0').perUserDataExportConfiguration()
config.param1 = 'something'
...
data = client.service.exportPerUserData(username,password,config)
Run Code Online (Sandbox Code Playgroud)
然后我明白了zeep.exceptions.ValidationError: Missing element param_i_didnt_set.看config.__values__演出
OrderedDict([('param1', 'something'),
('param_i_didnt_set', None), ...])
Run Code Online (Sandbox Code Playgroud)
该suds config对象的类似之处在于它包含许多带有空变量的键,但suds不会抛出ValidationErrors.
suds ×10
python ×9
soap ×3
xml ×2
arrays ×1
dictionary ×1
https ×1
json ×1
salesforce ×1
soap-client ×1
unicode ×1
web-services ×1
wsdl ×1
zeep ×1