我正在发送一个SOAP POST请求,但是在使用urllib2.urlopen(req)时出现了"HTTPError: HTTP Error 415: Unsupported Media Type"错误。
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:Header>
<AutotaskIntegrations xmlns="http://autotask.net/ATWS/v1_5/">
<PartnerID>1</PartnerID>
</AutotaskIntegrations>
</soap:Header>
<soap:Body>
<getThresholdAndUsageInfo xmlns="http://autotask.net/ATWS/v1_5/">
</getThresholdAndUsageInfo>
</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/getThresholdAndUsageInfo"'
}
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='george.lastname@domain.com',
passwd='mypw')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
page = urllib2.urlopen(site) #errors out 415 here
req = urllib2.Request(site, data, headers)
response = urllib2.urlopen(req)
我做错了什么?谢谢!
'Content-Length: "%d" % len(data)'
但是仍然出现相同的问题。 - George