Bad Request When calling SOAP request from Suds Python

Issue

This Content is from Stack Overflow. Question asked by Jaffer Saleem

When I call a SOAP request from suds python ,it is giving Bad request .I created the request objects from wsdl and pass the object to the method .It is throwing Bad request .Alternatively I sent the request as Raw XML ,it is also not working .Find the code below

   from suds.sax.text import Raw
   from suds.client import Client

   https = suds.transport.https.HttpTransport()
   urlvalue="https://wvuaxx.com:446/xxxrkView/DocumentService/DocumentService.svc?wsdl"
   client = Client(urlvalue ,unwrap=False)
   client.options.cache.clear()
   client.options.headers.clear()
   client.set_options(headers={"Content-type" : 'application/soap+xml; charset=UTF- 
   8','Soapaction': 
   'http://chubb.com/Workview/DocumentService/2016/06/DocumentService/GetSpecificDocument'})
   client.options.prettyxml = True
   client.options.autoblend  = True

   # Constructing request objects
   spcificdocumentrequest =client.factory.create('ns0:SpecificDocumentRequest')
  
   envrionmentdata=client.factory.create('ns0:EnvironmentData')
   envrionmentdata.MessageGUID = "msgId"
  
   spcificdocumentrequest.EnvironmentData=envrionmentdata

   logging.basicConfig(level=logging.DEBUG)
   logging.getLogger('suds.client').setLevel(logging.DEBUG)
   response =client.service.GetSpecificDocument(spcificdocumentrequest)
   print (response)
   ------------------------------------------------------------------------------------------- 
   xml=Raw("""<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
   xmlns:ns="http://chubb.com/Workview/DocumentService/2016/06"
   xmlns:ns1="http://chubb.com/WorkView/DocumentService/2016/06">
   <soap:Header/>
   <soap:Body>
  <ns:GetSpecificDocument>
     <!--Optional:-->
     <ns:request>
        <!--Optional:-->
        <ns1:DocumentGUID>D589A450-D3CA-4D55-8A0D-1D47E0DD01A2</ns1:DocumentGUID>
        <!--Optional:-->
        <ns1:IsSecurityCheckRequired></ns1:IsSecurityCheckRequired>
        <!--Optional:-->
        <ns1:UserId></ns1:UserId>
        <!--Optional:-->
        <ns1:FileNumber></ns1:FileNumber>
        <!--Optional:-->
        <ns1:FileType></ns1:FileType>
        <!--Optional:-->
        <ns1:EnvironmentData>
           <ns1:MessageGUID>Test-Message-guid</ns1:MessageGUID>
           <ns1:CountryCode>GB</ns1:CountryCode>
           <ns1:SourceSystem>TrackandTrace</ns1:SourceSystem>
           <ns1:WorkViewLogonID>TrackandTrace</ns1:WorkViewLogonID>
           <ns1:WorkViewEnvironment>UAT</ns1:WorkViewEnvironment>
        </ns1:EnvironmentData>
     </ns:request>
    </ns:GetSpecificDocument>
    </soap:Body>
    </soap:Envelope>
   """)

   response =client.service.GetSpecificDocument( __inject={'msg':xml})



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?