Python Forum
Object reference not set to an instance of an object When calling SOAP request
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object reference not set to an instance of an object When calling SOAP request
#2
Suds with Soap request as Raw xml is working after i used byte_str to convert the raw xml string to byte_str
please find the code .I used this from suds import byte_str .
But i am getting Object reference not set to an instance of an object when i pass as object instead of xml


import numpy as np # installed with matplotlib
import matplotlib.pyplot as plt
import logging
import suds
import ssl
import requests
import base64

def main():

  from suds.sax.element import Element
  from suds.sax.attribute import Attribute
  from suds import byte_str

  from suds.sax.text import Raw
  from suds.client import Client
  from suds.bindings import binding
  binding.envns=('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')
  from suds.plugin import MessagePlugin
  
  https = suds.transport.https.HttpTransport()
  urlvalue="https://wvua-eucluw-iws-446.aceins.com:446/WorkView/DocumentService/DocumentService.svc?wsdl"

  client = Client(urlvalue ,unwrap=False,transport=https)

  client.options.cache.clear()
  client.options.headers.clear()

  client.set_options(headers={"Content-type" : 'application/soap+xml; charset=UTF-8','SoapAction':'http://xxxx.com/xxxxyyyy/DocumentService/2016/06/DocumentService/GetSpecificDocument'})
  client.options.prettyxml = True
 
  #logging.basicConfig(level=logging.DEBUG)
  #logging.getLogger('suds.client').setLevel(logging.DEBUG)

  inputxml=Raw("""<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:ns0="http://xxxx.com/xxxyyyy/DocumentService/2016/06" xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:ns2="http://xxxx.com/xxxyyyy/DocumentService/2016/06">
   <SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <wsa:Action>http://xxxx.com/xxxyyyy/DocumentService/2016/06/DocumentService/GetSpecificDocument</wsa:Action>
      <wsa:To SOAP-ENV:mustUnderstand="true">https://xxxx.com/xxxyyyy/DocumentService/DocumentService.svc</wsa:To>
   </SOAP-ENV:Header>
   <ns1:Body>
      <ns0:GetSpecificDocument>
       <ns0:request>
         <ns2:DocumentGUID>0D7B80C9-4356-44D4-8C6E-4D479409F314</ns2:DocumentGUID>
         <ns2:EnvironmentData>
            <ns2:MessageGUID>msg-ID</ns2:MessageGUID>
            <ns2:CountryCode>GB</ns2:CountryCode>
            <ns2:SourceSystem>TrackandTrace</ns2:SourceSystem>
            <ns2:xxxxyyyyLogonID>TrackandTrace</ns2:xxxxyyyyLogonID>
            <ns2:xxxxyyyyEnvironment>UAT</ns2:xxxxyyyyEnvironment>
         </ns2:EnvironmentData>
      </ns0:request>
      </ns0:GetSpecificDocument>
   </ns1:Body>
</SOAP-ENV:Envelope>
""")

  message = byte_str(inputxml)

  try:
        print('Start...')
        specificDocumentResponse =client.factory.create('ns0:SpecificDocumentResponse')
        specificDocumentResponse =client.service.GetSpecificDocument(__inject={'msg': message})
    
        for item in specificDocumentResponse:
            extention = item[1].xxxxyyyyDocument.MimeType
            documentdata = item[1].xxxxyyyyDocument.DocumentData
        

        base64_img_bytes = documentdata.encode('utf-8')
        with open('test.'+extention, 'wb') as file_to_save:
             decoded_image_data = base64.decodebytes(base64_img_bytes)
             file_to_save.write(decoded_image_data)

        print ('Passed')
  except RuntimeError as detail:
        print ('Handling run-time error:'+ detail)

  
  print("passed")
main()
Larz60+ write Sep-30-2022, 04:47 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Please heed above. Continuing without using tags may lead to warning.
Fixed for you one more time.
Reply


Messages In This Thread
RE: Object reference not set to an instance of an object When calling SOAP request - by jaffersaleem - Sep-30-2022, 06:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  an object i would like to have Skaperen 3 1,101 Jun-09-2023, 08:09 AM
Last Post: Iusullin4235
  an object like a dictionary except ... Skaperen 1 1,154 Feb-27-2023, 07:55 PM
Last Post: Gribouillis
  TypeError: 'dict_items' object does not support indexingw Skaperen 3 2,613 May-06-2022, 10:52 PM
Last Post: Skaperen
  creating my own file-like object Skaperen 0 1,280 Feb-06-2022, 08:25 PM
Last Post: Skaperen
  how to destruct a hashlib object? Skaperen 2 1,756 Nov-29-2021, 07:24 PM
Last Post: Skaperen
  clearing a hashlib object Skaperen 0 1,869 Nov-28-2021, 07:54 PM
Last Post: Skaperen
  creating a dummy file object Skaperen 1 2,013 Oct-27-2021, 07:50 AM
Last Post: Gribouillis
  zero referenced object Skaperen 4 2,184 Oct-15-2021, 10:57 PM
Last Post: Skaperen
  object with ever possible attribute Skaperen 3 1,989 Jun-18-2020, 06:21 AM
Last Post: Skaperen
  i want to create my own file-like object Skaperen 0 2,137 Apr-17-2020, 11:47 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020