gpt4 book ai didi

python - XML SOAP POST 错误,我做错了什么?

转载 作者:数据小太阳 更新时间:2023-10-29 02:02:34 27 4
gpt4 key购买 nike

所以我正在尝试通过 XML SOAP POST 执行 API 调用,我得到的错误是:“对象引用未设置为对象的实例”

site = 'https://webservices.autotask.net/atservices/1.5/atws.asmx'
data = """<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<queryxml>
<entity>contact</entity>
<query>
<field>firstname<expression op="equals">George</expression>
</field>
</query>
</queryxml>
</soap:Body>
</soap:Envelope>"""

headers = {
'Content-Type': 'application/soap+xml; charset=utf-8',
'Host': 'webservices.autotask.net',
'Content-Type': 'text/xml; charset=utf-8',
'Content-Length': len(data),
'SOAPAction': "http://autotask.net/ATWS/v1_5/query"
}
site = 'https://webservices.autotask.net/atservices/1.5/atws.asmx'
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='webservices.autotask.net',
uri=site,
user='user,
passwd='pw')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
page = urllib2.urlopen(site)
print(data)
req = urllib2.Request(site, data, headers)
response = urllib2.urlopen(req)
the_page = response.read()
print(the_page)

身份验证有效,我已使用此代码成功调用,现在唯一不同的是数据 XML SOAP POST。我会试试 SOAP 水。

没有 Traceback 只有 web 服务器错误:

打印出我发送的 XML SOAP POST:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<queryxml>
<entity>contact</entity>
<query>
<field>firstname<expression op="equals">George</expression>
</field>
</query>
</queryxml>
</soap:Body>
</soap:Envelope>

响应:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><queryResponse xmlns="http://autotask.net/ATWS/v1_5/"><queryResult><ReturnCode>-1</ReturnCode><EntityResults /><EntityResultType /><Errors><ATWSError><Message>Object reference not set to an instance of an object.</Message></ATWSError><ATWSError><Message>Error reading in Query XML.</Message></ATWSError></Errors><EntityReturnInfoResults /></queryResult></queryResponse></soap:Body></soap:Envelope>

有什么想法吗?

乔治

最佳答案

Autotask 在 IIS 6 上有一个古老的 API... 要处理 Microsoft crapstack,您必须转义您作为 CDATA 推送到那里的 XML。这是对我有用的 SOAP 主体,在

<ins0:query> 

标签:

<ins0:sXML>
<![CDATA[<queryxml>
<entity>contact</entity>
<query>
<field>phone<expression op='equals'>#{phone}</expression></field>
</query>
</queryxml>]]>
</ins0:sXML>

关于python - XML SOAP POST 错误,我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5227333/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com