所以我试图做通过XML SOAP的API调用后,我得到的错误是:“未将对象引用设置到对象的实例”XML SOAP POST错误,我在做什么错误?
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)
中的授权作品,我已经做了succesfull使用此代码调用,现在唯一不同的是XML SOAP POST数据。我会尝试泡沫。
没有回溯只有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>
任何想法?
乔治
不,根本没有想法。不过,如果您发布了您正在使用的代码以及所获得的回溯,我可能会有一些。 – 2011-03-08 01:35:37
你确定你使用python而不是.NET? – 2011-03-08 01:35:52
您是否正在手动构建SOAP POST正文?使用[python-suds](http://pypi.python.org/pypi/suds)可以更轻松地调用您的SOAP服务。 – samplebias 2011-03-08 02:10:22