soapi获取Cookie

2024-09-30 18:27:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用soapi获取一个认证密钥,其中包含一个cookie,该cookie应该返回

from zeep import Client
client = Client("AuthenticationService.xml")
result = client.service.ValidateUser(username, password, "")
result

然而,结果是,我得到了一个布尔值True,但没有包含身份验证密钥的Cookie

从下图中,您可以看到使用SoapUI的相同请求返回一个cookie。我想知道如何在Python中实现这一点

SoapUI Software Response


Tags: fromimportclienttruecookieservice密钥username
1条回答
网友
1楼 · 发布于 2024-09-30 18:27:01

为了能够处理cookie,我们必须对transport使用requests.Session

因此,对于您来说,一个简单的用例如下所示:

from zeep import Client
from requests import Session
from zeep.transports import Transport

session = Session()
# disable TLS verification
session.verify = False

transport = Transport(session=session)

client = Client("AuthenticationService.xml", transport=transport)

result = client.service.ValidateUser(username, password, "")

# then check cookie
client.transport.session.cookies

希望这有帮助

相关问题 更多 >