所以我試圖做通過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