-1

So I have a username and password, and I have a ClientID. With JSON I can just create a header field to add these in and do a requests.post(endpoint, json=payload, headers=my_headers), but for SOAP the header fields are {content-type': 'application/soap+xml'} and auth= takes username and password. So what happens to my ClientID or where do I initialize it?

First I will start off with what I tried using Zeep for Python.

from requests.auth import HTTPBasicAuth
from requests import Session
from zeep.transports import Transport
from zeep import Client, Settings

#Client-ID
client_id = '7777'

username = 'jj'
password = 'tt'

#this endpoint ends with .svc, not sure if that matters but even if I were to add ?wsdl I get 400 error
wsdl = 'endpoint_url_.svc'

settings = Settings(strict=False, xml_huge_tree=True)


session = Session()
session.auth = HTTPBasicAuth(username, password)
client = Client(wsdl, settings=settings, # the Client field here doesn't take ClientID but my endpoint
            transport=Transport(session=session))

So Zeep says to run python -mzeep wsdl to get soap methods but this is my output: Prefixes: xsd: http://www.w3.org/2001/XMLSchema

Global elements:

Global types: xsd:anyType xsd:ENTITIES xsd:ENTITY xsd:ID xsd:IDREF xsd:IDREFS xsd:NCName xsd:NMTOKEN xsd:NMTOKENS xsd:NOTATION xsd:Name xsd:QName xsd:anySimpleType xsd:anyURI xsd:base64Binary xsd:boolean xsd:byte xsd:date xsd:dateTime xsd:decimal xsd:double xsd:duration xsd:float xsd:gDay xsd:gMonth xsd:gMonthDay xsd:gYear xsd:gYearMonth xsd:hexBinary xsd:int xsd:integer xsd:language xsd:long xsd:negativeInteger xsd:nonNegativeInteger xsd:nonPositiveInteger xsd:normalizedString xsd:positiveInteger xsd:short xsd:string xsd:time xsd:token xsd:unsignedByte xsd:unsignedInt xsd:unsignedLong xsd:unsignedShort

Bindings:

So even if I do this, none of my methods show at service. result = client.service.(some method)

  1. Second attempt without Zeep. Now for some reason the soap data example for the body looks like this.

    import requests from requests.auth import HTTPBasicAuth

    soap_body = '''

    1

    D

    0

    ex

    5 '''

From examples and SOAP calls I've read and seen online it is missing envelope, body, and header, but let's assume this is the correct xml for making the post request.

headers = {'content-type': 'application/soap+xml'}
url = 'endpoint_url.svc'

username = 'jj'
password= 'tt'
client_id = '7777'

response = requests.post(url, data=soap_body, headers=headers, auth=HTTPBasicAuth(username, password))
print(response)
print(response.content)

Ouput I get <Response [415]> b''

The requests.post doesn't seem to take a ClientID field. How would I initialize this first? Any suggestions or recommendations appreciated. Thank you for your time.

JT Saiyan
  • 55
  • 1
  • 7
  • For some reason my soap body didn't turn out right, but here is how its suppose to look like 1 T 1 ex 5 – JT Saiyan Sep 11 '20 at 17:11

1 Answers1

0

I couldn't find this in a documentation anywhere, but the Client ID can be placed inside the headers as well. headers = {'content-type': 'application/soap+xml', 'Client-ID':'123'}

JT Saiyan
  • 55
  • 1
  • 7