从 SUDS 中的 SOAP 响应中提取 Cookie [英] Extracting Cookie from SOAP Response in SUDS
问题描述
我必须使用具有多项服务的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!