将 Cookie 添加到 ZSI 帖子
我通过重写 HTTPTransport 向 SOAPpy 添加了 cookie 支持。 我需要 SOAPpy 之外的功能,因此我计划转向 ZSI,但我不知道如何将 Cookie 放在向该服务发布的 ZSI 帖子上。 如果没有这些cookie,服务器会认为这是未经授权的请求,并且会失败。
如何将 Python CookieJar 中的 cookie 添加到 ZSI 请求?
I've added cookie support to SOAPpy by overriding HTTPTransport. I need functionality beyond that of SOAPpy, so I was planning on moving to ZSI, but I can't figure out how to put the Cookies on the ZSI posts made to the service. Without these cookies, the server will think it is an unauthorized request and it will fail.
How can I add cookies from a Python CookieJar to ZSI requests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您阅读了 ZSI 的 client.py 中的 _Binding 类 可以看到它有一个变量 cookies,它是 Cookie 的实例.SimpleCookie。 遵循 ZSI 示例 和 Cookie 示例 这就是它应该如何工作:
If you read the _Binding class in client.py of ZSI you can see that it has a variable cookies, which is an instance of Cookie.SimpleCookie. Following the ZSI example and the Cookie example that is how it should work:
此外,Binding 类还允许添加任何标头。 所以我发现我可以为每个需要添加的 cookie 添加一个“Cookie”标头。 这对于 wsdl2py 生成的代码效果很好,只需在 SOAP 客户端类中形成绑定后立即添加 cookie。 向生成的类添加参数以将 cookie 作为字典接收很容易,然后可以轻松地迭代和添加它们。
Additionally, the Binding class also allows any header to be added. So I figured out that I can just add a "Cookie" header for each cookie I need to add. This worked well for the code generated by wsdl2py, just adding the cookies right after the binding is formed in the SOAP client class. Adding a parameter to the generated class to take in the cookies as a dictionary is easy and then they can easily be iterated through and added.