HTTP错误415我在做什么错? [英] HTTP error 415 what am I doing wrong?
本文介绍了HTTP错误415我在做什么错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在发送SOAP POST,并且收到"HTTPError:HTTP错误415:不支持的媒体类型" @ response = urllib2.urlopen(req)
I am sending a SOAP POST and I am getting a "HTTPError: HTTP Error 415: Unsupported Media Type" @ response = urllib2.urlopen(req)
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)
我做错了什么?谢谢!
推荐答案
headers
词典中的Content-Length
值似乎错误
'Content-Length: len(data)'
以及其他一些值.
我将通过以下方式修复它:
I would fix it with:
headers = {
'Content-Type': 'application/soap+xml; charset=utf-8',
'Host': 'webservices.autotask.net',
'Content-Length': len(data),
'SOAPAction': 'http://autotask.net/ATWS/v1_5/getThresholdAndUsageInfo'
}
这篇关于HTTP错误415我在做什么错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文