使用 SUDS 清空 cookiejar
我正在 Linux Slackware 13.0 上使用 python 2.6.2 运行 SUDS 0.4。当我使用此代码调用 SOAP 方法时:
from suds.client import Client
client = Client(url='file:acctWeb.wsdl',
location='http://10.242.69.4:8088/pfmaccess')
res = client.service.login(login='user',password='passwd')
我收到以下响应:
DEBUG:suds.transport.http:received:
CODE: 200
HEADERS: {'set-cookie': 'OSP_Ref=0000000573800052;Domain=10.242.69.4:8088;Path=/pfmaccess', 'content-length': '26541', 'content-type': 'text/xml; charset=utf-8', 'connection': 'close', 'server': 'Alcatel-Lucent OSP 2.4'}
但
>>> client.options.transport.cookiejar
<cookielib.CookieJar[]>
显示没有可用的 cookie。原因可能是什么?我无法使用 SOAP API,因为我需要传递在响应 cookie 中发送的凭据。
请帮我解决这个问题。
BR
詹
I'm running SUDS 0.4 on Linux Slackware 13.0 with python 2.6.2. When I call SOAP method using this code:
from suds.client import Client
client = Client(url='file:acctWeb.wsdl',
location='http://10.242.69.4:8088/pfmaccess')
res = client.service.login(login='user',password='passwd')
I receive following response:
DEBUG:suds.transport.http:received:
CODE: 200
HEADERS: {'set-cookie': 'OSP_Ref=0000000573800052;Domain=10.242.69.4:8088;Path=/pfmaccess', 'content-length': '26541', 'content-type': 'text/xml; charset=utf-8', 'connection': 'close', 'server': 'Alcatel-Lucent OSP 2.4'}
but
>>> client.options.transport.cookiejar
<cookielib.CookieJar[]>
shows that there are no cookies available. What could be a reason for that? I'm not able to use SOAP API because I need to pass credentials sent in response cookie.
Please help me on this.
BR
rjan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我已经玩了一下。
首先,一个小测试服务器(由soaplib提供):
有一些修改以设置 cookie 标头。
和一个 suds-testclient:
运行它会产生:
所以它看起来可以工作。但是如果您将请求网址更改为
http://localhost:7789/?wsdl
您将得到:在客户端打开
cookielib
的一些日志记录...。 ..它揭示了原因:
简单的解释是:cookie 域与请求的服务器域不匹配,并且看起来
cookielib
在验证域时不会进行任何查找。所以解决方案是以下之一:
在示例中我必须将两者设置为
localhost.local
才能使其工作(可能取决于hosts
文件...)cookieib
使用请求域自动哦,最后但并非最不重要的是:它在OP问题:
该端口不是域的一部分,因此带有
Domain=10.242.69.4:8088
的 cookie 将始终被拒绝。Ok, i've played around a bit with it.
first, a little test server (courtesy of soaplib):
with some little modification to set a cookie header.
and a suds-testclient:
running this produces:
so it seams to work. but if you change the request url to
http://localhost:7789/?wsdl
you'll get:turning on some logging for
cookielib
at the client...... and it reveals reveals why:
the simple explanation is: the cookie domain does not match the request's server domain, and as it seems
cookielib
does not do any lookup when verifying the domain.so the solution would be one of:
in the example i have to set both to
localhost.local
to make it work (may depend on thehosts
file...)cookieib
uses the request domain automaticallyOh, and last but not least: the reason why it didn't work in the OPs question:
the port is not part of the domain, therfore a cookie with
Domain=10.242.69.4:8088
will always be rejected.