Soap ошибка 415

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

71.5k47 gold badges168 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

Description:

I am trying to convert a SOAP Endpoint to a REST Endpoint using WSO2. While creating and sending the request in API Manager , I am getting 415 Error: Unsupported Media Type as response.

Steps to reproduce:

I am trying to convert a SOAP Endpoint to a REST Endpoint using WSO2. While creating and sending the request in API Manager , I am getting 415 Error: Unsupported Media Type as response.
On analysis, i found that Content-Type is coming as application/soap+xml, although it should come as «text/xml» .
Now to change that, I am
going to the Resources section — In-mediation and changing the value of messageType and it saves, but when i go and re-open the in-mediation again, the value gets re-setted to what it was earlier. (application/soap+xml in my case). These changes are done using the admin user. Is there any other place where I need to change it or some other file is overriding this change?
I believe this is a bug. Please fix it.
I am using WSO2 API Manager 4.0.0

Affected Product Version:

WSO2 API Manager 4.0.0

Environment details (with versions):

  • OS: Windows
  • Client: API Manager
  • Env (Docker/K8s):

Optional Fields

Related Issues:

Suggested Labels:

Suggested Assignees:

Fix :
» «

this time i will be needing some help with an error that i can’t find where is the problem.

I developed a very simple java code to consume a web service but when I run it i’m getting this nasty error: «Caused by: java.io.IOException: Server returned HTTP response code: 415 for URL: http://www.dataaccess.com/webservicesserver/numberconversion.wso/NumberToWords»

Investigating about this error it said that this has something to do with the Content-Type not been supported, so downloaded SoapUI 5.6.0 to see what the WS was waiting for and it seems correct to me.

Here is my code:

package principal;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class PruebaWS {
    public void getNumber(int number){
        String wsURL = "http://www.dataaccess.com/webservicesserver/numberconversion.wso/NumberToWords";
        URL url = null;
        URLConnection connection = null;
        HttpURLConnection httpConn = null;
        String responseString = null;
        String outputString = null;
        ByteArrayOutputStream bout = null;
        OutputStream out = null;
        InputStreamReader isr = null;
        BufferedReader in = null;
        
        String xmlInput = 
                "<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.dataaccess.com/webservicesserver/">" +
                "   <soapenv:Header/>" +
                "   <soapenv:Body>" +
                "      <web:NumberToWords>" +
                "         <web:ubiNum>" + number +"</web:ubiNum>" +
                "      </web:NumberToWords>" +
                "   </soapenv:Body>" +
                "</soapenv:Envelope>";
        
        try {
            url = new URL(wsURL);
            connection = url.openConnection();
            httpConn = (HttpURLConnection) connection;
            
            byte[] buffer = new byte[xmlInput.length()];
            buffer = xmlInput.getBytes();
            
            String SOAPAction = "";
            httpConn.setRequestMethod("POST");
            httpConn.setRequestProperty("SOAPAction", SOAPAction);
            httpConn.setRequestProperty("Content-Length", String.valueOf(buffer.length));
            httpConn.setRequestProperty("Content-Type", "text/xml;charset=utf-8");
            httpConn.setRequestProperty("Accept", "*/xml");
            httpConn.setDoInput(true);
            httpConn.setDoOutput(true);
            httpConn.setUseCaches(false);
            
            out = httpConn.getOutputStream();
            out.write(buffer);
            out.close();
            
            // Lee la respuesta y escribe a un output estándard
            isr = new InputStreamReader(httpConn.getInputStream());
            in = new BufferedReader(isr);
            
            while ((responseString = in.readLine()) != null)
                outputString = outputString + responseString;
            
            System.out.println(outputString);
            System.out.println("");
            
            // Obtiene la respuesta desde la llamada al webService
            Document document = parseXmlFile(outputString);
            
            NodeList nodeList = document.getElementsByTagName("m:NumberToWordsResponse");
            String webServiceResponse = nodeList.item(0).getTextContent();
            System.out.println("La respuesta del web service es: " + webServiceResponse);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    
    private Document parseXmlFile(String in){
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource is = new InputSource(new StringReader(in));
            return db.parse(is);
        } catch (ParserConfigurationException | SAXException | IOException e) {
            throw new RuntimeException(e);
        }
    }
}

And this is the error during Runtime:

Exception in thread «main» java.lang.RuntimeException:
java.io.IOException: Server returned HTTP response code: 415 for URL:
http://www.dataaccess.com/webservicesserver/numberconversion.wso/NumberToWords
at principal.PruebaWS.getNumber(PruebaWS.java:83) at
principal.Main.main(Main.java:6) Caused by: java.io.IOException:
Server returned HTTP response code: 415 for URL:
http://www.dataaccess.com/webservicesserver/numberconversion.wso/NumberToWords
at
java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1919)
at
java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)
at principal.PruebaWS.getNumber(PruebaWS.java:67) … 1 more
C:LocalNetBeansCache11.1executor-snippetsrun.xml:111: The
following error occurred while executing this line:
C:LocalNetBeansCache11.1executor-snippetsrun.xml:68: Java
returned: 1 BUILD FAILED (total time: 2 seconds)

Any help will be valuable.

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

Понравилась статья? Поделить с друзьями:
  • Sony vegas выдает ошибку при рендеринге
  • Sony vegas pro ошибка при открытии кодека
  • Sony vegas pro 13 ошибка при визуализации
  • Sony vegas pro 13 quicktime ошибка
  • Sony vaio ошибка 333