views:

312

answers:

2

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?

+1  A: 

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:

b = Binding(url='/cgi-bin/simple-test', tracefile=fp)
b.cookies['foo'] = 'bar'
Florian Bösch
A: 

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.

danivovich