Soap 415 error

I am sending a SOAP POST and I am getting a "HTTPError: HTTP Error 415: Unsupported Media Type" @ response = urllib2.urlopen(req) data = """ <soap:En...

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

George's user avatar

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'
}

Daniel Lubarov's user avatar

answered Mar 6, 2011 at 21:53

systempuntoout's user avatar

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()

Community's user avatar

answered Dec 21, 2011 at 22:55

AltruXeno's user avatar

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

John Wagenleitner's user avatar

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

George's user avatar

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'
}

Daniel Lubarov's user avatar

answered Mar 6, 2011 at 21:53

systempuntoout's user avatar

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()

Community's user avatar

answered Dec 21, 2011 at 22:55

AltruXeno's user avatar

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

John Wagenleitner's user avatar

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 code

    Dim 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 Then

    End 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 415

SOAP 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
<?xml version=»1.0″ ?><S:Envelope xmlns:S=»http://schemas.xmlsoap.org/soap/envelope/»><S:Body><ns2:ProcessFluidAnalysisIP xmlns=»http://schema.v1_0.fluidanalysis.cbm.deere.com/» xmlns:ns2=»http://cbm.deere.com/v1_0/FluidAnalysisSchema»><ns2:labName>test</ns2:labName><ns2:fluidAnalysisXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;fluidAnalysisResults xmlns=&quot;http://schema.v1_0.fluidanalysis.cbm.deere.com/&quot;&gt;&lt;fluidAnalysisResult&amp;gt;&;lt;fluidAnalysisData&gt;&amp;lt;fluidSample&amp;gt;&;lt;sampleCondition&amp;gt;Caution&lt;/sampleCondition&amp;gt;&;lt;recommendation&amp;gt;Note:  Viscosity Appears To Be Low. Viscosity And Fuel Result Confirmed In Retest. Sample Form Indicates Oil/Filter Changed At Time Of Sampling. Results Reported Via Email.&lt;/recommendation&gt;&lt;sampleObtainedDate&gt;2010-02-26&lt;/sampleObtainedDate&gt;&lt;sampleTestedDate&gt;2010-03-02&lt;/sampleTestedDate&gt;&lt;hoursAtSample&gt;&lt;hoursOnFluid&gt;500&lt;/hoursOnFluid&gt;&lt;hoursOnMachine&gt;0&lt;/hoursOnMachine&gt;&lt;/hoursAtSample&gt;&lt;componentType&gt;E&lt;/componentType&gt;&lt;fluidBrand&gt;John Deere&lt;/fluidBrand&gt;&lt;fluidType&gt;Plus-50&lt;/fluidType&gt;&lt;systemFuelType /&gt;&lt;sampleFrequency&gt;0&lt;/sampleFrequency&gt;&lt;/fluidSample&gt;&lt;variableTests&gt;&lt;name&gt;TBN&lt;/name&gt;&lt;value&gt;9.3&lt;/value&gt;&lt;/variableTests&gt;&lt;elementalData&gt;&lt;Ag_Silver&gt;1&lt;/Ag_Silver&gt;&lt;Al_Aluminum&gt;3&lt;/Al_Aluminum&gt;&lt;B_Boron&gt;84&lt;/B_Boron&gt;&lt;Ba_Barium&gt;1&lt;/Ba_Barium&gt;&lt;Ca_Calcium&gt;3455&lt;/Ca_Calcium&gt;&lt;Cr_Chromium&gt;2&lt;/Cr_Chromium&gt;&lt;Cu_Copper&gt;10&lt;/Cu_Copper&gt;&lt;Fe_Iron&gt;50&lt;/Fe_Iron&gt;&lt;K_Potassium&gt;5&lt;/K_Potassium&gt;&lt;Mg_Magnesium&gt;57&lt;/Mg_Magnesium&gt;&lt;Mn_Manganese&gt;2&lt;/Mn_Manganese&gt;&lt;Mo_Molybdenum&gt;97&lt;/Mo_Molybdenum&gt;&lt;Na_Sodium&gt;4&lt;/Na_Sodium&gt;&lt;Ni_Nickel&gt;1&lt;/Ni_Nickel&gt;&lt;P_Phosphorus&gt;1424&lt;/P_Phosphorus&gt;&lt;Pb_Lead&gt;3&lt;/Pb_Lead&gt;&lt;Si_Silicon&gt;5&lt;/Si_Silicon&gt;&lt;Sn_Tin&gt;1&lt;/Sn_Tin&gt;&lt;Ti_Titanium&gt;1&lt;/Ti_Titanium&gt;&lt;V_Vanadium&gt;1&lt;/V_Vanadium&gt;&lt;Zn_Zinc&gt;1919&lt;/Zn_Zinc&gt;&lt;/elementalData&gt;&lt;physicalProperties&gt;&lt;viscosity_40&gt;51.3&lt;/viscosity_40&gt;&lt;viscosity_100&gt;N/A&lt;/viscosity_100&gt;&lt;fuelDilution&gt;&amp;lt;1&lt;/fuelDilution&gt;&lt;waterPercentage&gt;0.05&lt;/waterPercentage&gt;&lt;solidsPercentage&gt;N/A&lt;/solidsPercentage&gt;&lt;glycol&gt;NO&lt;/glycol&gt;&lt;flashPoint /&gt;&lt;grade&gt;SAE 15W40&lt;/grade&gt;&lt;/physicalProperties&gt;&lt;particleCountData&gt;&lt;pc1&gt;173403&lt;/pc1&gt;&lt;pc2&gt;44057&lt;/pc2&gt;&lt;pc3&gt;876&lt;/pc3&gt;&lt;pc4&gt;132&lt;/pc4&gt;&lt;pc5&gt;0&lt;/pc5&gt;&lt;pcInfo&gt;&amp;gt;4; &amp;gt;6; &amp;gt;14; &amp;gt;23; &amp;gt;50NNNNN&lt;/pcInfo&gt;&lt;/particleCountData&gt;&lt;/fluidAnalysisData&gt;&lt;labInformation&gt;&lt;componentId&gt;6824398&lt;/componentId&gt;&lt;labYear&gt;2010&lt;/labYear&gt;&lt;deptNumber&gt;410&lt;/deptNumber&gt;&lt;labNo&gt;41010035036&lt;/labNo&gt;&lt;cno&gt;6177831&lt;/cno&gt;&lt;batchNumber&gt;2823&lt;/batchNumber&gt;&lt;analystId&gt;166&lt;/analystId&gt;&lt;ctcNumber&gt;1&lt;/ctcNumber&gt;&lt;/labInformation&gt;&lt;machineInformation&gt;&lt;make /&gt;&lt;model /&gt;&lt;pin&gt;DW724KX625796&lt;/pin&gt;&lt;/machineInformation&gt;&lt;contactInformation&gt;&lt;companyName&gt;NA_Murphy Tractor &amp;amp; Equipment&lt;/companyName&gt;&lt;contactLastName&gt;Savage&lt;/contactLastName&gt;&lt;contactFirstName&gt;Savage, Mark&lt;/contactFirstName&gt;&lt;address1 /&gt;&lt;address2 /&gt;&lt;city&gt;Omaha&lt;/city&gt;&lt;state&gt;NE&lt;/state&gt;&lt;zipCode&gt;68138&lt;/zipCode&gt;&lt;phone&gt;4028941899&lt;/phone&gt;&lt;fax&gt;4028918360&lt;/fax&gt;&lt;divisionNumber /&gt;&lt;unitDescription&gt;Diesel Engine&lt;/unitDescription&gt;&lt;serviceOrSerialNumber /&gt;&lt;parentNumber /&gt;&lt;endUser&gt;&lt;/endUser&gt;&lt;endLocation&gt;&lt;/endLocation&gt;&lt;/contactInformation&gt;&lt;/fluidAnalysisResult&gt;&lt;/fluidAnalysisResults&gt;</ns2:fluidAnalysisXML></ns2:ProcessFluidAnalysisIP></S:Body></S:Envelope>
ENDTEXT

objh = CREATEOBJECT(«Microsoft.XMLHTTP»)
objh.OPEN(«POST»,»https://cbm.tal.deere.com/cbm/services/FluidAnalysis_1_0″,»false»,»GUCF135″,»fluid123″)
objh.SEND (xmlout)

    * wait for server to respond
DO WHILE objh.readyState <> 4
ENDDO

    MESSAGEBOX(objh.responseText,16,»Return Message»)
MESSAGEBOX(objh.STATUS,16,»Return Code»)

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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:

  • Tek-Tips ForumsTalk 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

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Socket error 10022 delphi
  • So open error sxxapi01
  • So error 31233
  • Sntp server communication error oki
  • Snowrunner тормозит как исправить

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии