本文介绍了从SUDS中的SOAP响应中提取Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用具有多种服务的API.所有这些都需要以下身份验证中的JSESSION cookie.但是,当我调用下一个服务时,它不会保留cookie,因此会拒绝它们.

I have to work with an API that has multiple services. All of which require the JSESSION cookie from the authentication one below. When I call the next service however, it doesn't keep the cookie and so 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/>]>

我相信获取它以保留此cookie的方法是提取它,然后将其作为自定义标头以以下格式提供:-

I believe that the way to get it to keep this cookie is to extract it, then provide it as a custom header in the format: -

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

但是我不知道该怎么做.我已经查看了SUDS文档,URL2LIB和Cookiejar python文档,并查看了堆栈&在Reddit上问.这是我在Stack上提出的第一个问题,我试图使其有意义且具体,但是如果我提出了虚假的建议,请告诉我,我将尽力予以纠正.

But I can't figure out how to do it. I've reviewed the SUDS Docs, URL2LIB and Cookiejar python docs, looked over stack & asked on Reddit. This is the first question I've asked on Stack, I've tried to make it meaningful and specific, but if I've commited a faux par, tell me and I'll do my best to correct it.

推荐答案

尝试一下.

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

这篇关于从SUDS中的SOAP响应中提取Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:25