Extract cookie from SOAP response in SUDS

I need to work with an API that has several services. All of them require the JSESSION cookie to be authenticated below. However, when I call the following service, it does not save the cookie and therefore rejects them.

from suds.client import Client
url = 'http://example/ws/Authenticate?wsdl'
client = Client(url)
result = client.service.connect(username='admin', password='admin')
print client.options.transport.cookiejar

>>> <cookielib.CookieJar[<Cookie JSESSIONID=XXXXXXXXXX for localhost.local/Service/>]>

I believe that the way to make it save this cookie is to extract it and then provide it as a custom header in the format: -

url = 'http://example/ws/dostuffnowloggedin?wsdl' 
client2 = Client(url, headers= { 'Cookie': 'JSESSIONID=value'})

But I can’t figure out how to do this. I looked at the SUDS Docs, URL2LIB and Cookiejar python docs, looked at the stack and asked Reddit. This is the first question I asked in Stack, I tried to make it meaningful and specific, but if I made a mistake, tell me and I will do my best to fix it.

+3
source share
1

.

from suds.client import Client
url = 'http://example/ws/Authenticate?wsdl'
client = Client(url)
result = client.service.connect(username='admin', password='admin')
url2='url of second service'
client2=Client(url2)
client2.options.transport.cookiejar=client.options.transport.cookiejar
0

All Articles