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)
What am I doing wrong? Thanks!
asked Mar 6, 2011 at 21:51
The Content-Length
value in the headers
dictionary seems wrong
'Content-Length: len(data)'
and also some other values.
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'
}
answered Mar 6, 2011 at 21:53
systempuntooutsystempuntoout
71k46 gold badges167 silver badges241 bronze badges
3
I know that this is fixed, but I spent quite a while with the same error and with no workable solution and wanted to get this solution out there in case someone else was having the same issue that I was. After several hours of searching I noticed that the file I was looking at was using SOAP v1.2. This is potentially a problem because Suds (to my knowledge) doesn’t yet support v1.2.
I found a workaround to make Suds think that it is using v1.2 here: SOAP 1.2 python client. I’m sure this won’t work for everyone, as this 415 error can be caused by many different things, but it worked for me and there are very few solutions to this problem so the more we can get here the better. I’ve pasted the code that worked for me below (there were a few potential solutions on that page).
from suds.client import Client
from suds.bindings import binding
import logging
USERNAME = 'username'
PASSWORD = 'password'
# Just for debugging purposes.
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# Telnic's SOAP server expects a SOAP 1.2 envelope, not a SOAP 1.1 envelope
# and will complain if this hack isn't done.
binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
client = Client('client.wsdl',
username=USERNAME,
password=PASSWORD,
headers={'Content-Type': 'application/soap+xml'})
# This will now work just fine.
client.service.someRandomMethod()
answered Dec 21, 2011 at 22:55
In the headers you have Content-Type listed twice.
The message you are sending is using the SOAP 1.1 namespace which would match the second Content-Type (text/xml). Based on the error I would guess the first Content-Type (application/soap+xml), which is for SOAP 1.2 message is actually being sent to the server. Remove the first Content-Type, that should fix if your server is truly expecting a SOAP 1.1 message.
answered Mar 6, 2011 at 21:59
1
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)
What am I doing wrong? Thanks!
asked Mar 6, 2011 at 21:51
The Content-Length
value in the headers
dictionary seems wrong
'Content-Length: len(data)'
and also some other values.
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'
}
answered Mar 6, 2011 at 21:53
systempuntooutsystempuntoout
71k46 gold badges167 silver badges241 bronze badges
3
I know that this is fixed, but I spent quite a while with the same error and with no workable solution and wanted to get this solution out there in case someone else was having the same issue that I was. After several hours of searching I noticed that the file I was looking at was using SOAP v1.2. This is potentially a problem because Suds (to my knowledge) doesn’t yet support v1.2.
I found a workaround to make Suds think that it is using v1.2 here: SOAP 1.2 python client. I’m sure this won’t work for everyone, as this 415 error can be caused by many different things, but it worked for me and there are very few solutions to this problem so the more we can get here the better. I’ve pasted the code that worked for me below (there were a few potential solutions on that page).
from suds.client import Client
from suds.bindings import binding
import logging
USERNAME = 'username'
PASSWORD = 'password'
# Just for debugging purposes.
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# Telnic's SOAP server expects a SOAP 1.2 envelope, not a SOAP 1.1 envelope
# and will complain if this hack isn't done.
binding.envns = ('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
client = Client('client.wsdl',
username=USERNAME,
password=PASSWORD,
headers={'Content-Type': 'application/soap+xml'})
# This will now work just fine.
client.service.someRandomMethod()
answered Dec 21, 2011 at 22:55
In the headers you have Content-Type listed twice.
The message you are sending is using the SOAP 1.1 namespace which would match the second Content-Type (text/xml). Based on the error I would guess the first Content-Type (application/soap+xml), which is for SOAP 1.2 message is actually being sent to the server. Remove the first Content-Type, that should fix if your server is truly expecting a SOAP 1.1 message.
answered Mar 6, 2011 at 21:59
1
- Remove From My Forums
-
Question
-
User1897897189 posted
Dear all,
I am developing a wcf service which will send XML to a service outside my office.
Following is my codeDim xml As String
xml = «http://send/p1/?xml=<?xml version=»»1.0″» encoding=»»utf-8″»?>» +
«<Emp ID=»»1234″»>» +
«<EmpDtls>» +
«<Empno>» & Empno & «</empno>» +
«</EmpDtls>» +
«</Emp>»
Dim url As String = «http://send/p1»
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim requestBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(xml)
req.Method = «POST»
req.ContentType = «text/xml;charset=utf-8»
req.ContentLength = requestBytes.Length
Dim requestStream As Stream = req.GetRequestStream()
requestStream.Write(requestBytes, 0, requestBytes.Length)
requestStream.Close()
Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
If res.StatusCode = HttpStatusCode.OK ThenEnd If
Dim sr As New StreamReader(res.GetResponseStream(), System.Text.Encoding.[Default])
Dim backstr As String = sr.ReadToEnd()
sr.Close()
res.Close()I am getting following error message. Please help me to rectify this issue.
The remote server returned an error: (415) Unsupported Media Type.Web.config
<system.net>
<defaultProxy>
<proxy usesystemdefault=»False»/>
</defaultProxy>
</system.net><system.web>
<compilation debug=»true» strict=»false» explicit=»true» targetFramework=»4.0″ />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!— To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment —>
<serviceMetadata httpGetEnabled=»true»/>
<!— To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information —>
<serviceDebug includeExceptionDetailInFaults=»false»/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled=»true» />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests=»true»/>
</system.webServer>Thanks
nick
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Contact US
Thanks. We have received your request and will respond promptly.
Log In
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips Forums!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts - Keyword Search
- One-Click Access To Your
Favorite Forums - Automated Signatures
On Your Posts - Best Of All, It’s Free!
*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Students Click Here
SOAP request fails error 415SOAP request fails error 415(OP) 31 Aug 10 16:28 I am new to SOAP and have been supplied the following message to send as a test but I keep getting error 415 returned. Here is the test program TEXT TO xmlout noshow objh = CREATEOBJECT(«Microsoft.XMLHTTP») * wait for server to respond MESSAGEBOX(objh.responseText,16,»Return Message») Red Flag SubmittedThank you for helping keep Tek-Tips Forums free from inappropriate posts. |
Join Tek-Tips® Today!
Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.
Here’s Why Members Love Tek-Tips Forums:
Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More…
Register now while it’s still free!
Already a member? Close this window and log in.
Join Us Close