Empty cookiejar using SUDS

I am running SUDS 0.4 on Linux Slackware 13.0 using python 2.6.2. When I call the SOAP method with 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 get the following answer:

 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[]> 

indicates that cookies are not available. What could be the reason for this? I cannot use the SOAP API because I need to pass the credentials sent in the response cookie.

Please help me with this.

BR

rjan

+7
source share
1 answer

Ok, I played a little with him.

first a small test server ( courtesy of soaplib ):

 import soaplib from soaplib.core.service import rpc, DefinitionBase, soap from soaplib.core.model.primitive import String, Integer from soaplib.core.server import wsgi from soaplib.core.model.clazz import Array import sys, pprint class HelloWorldService(DefinitionBase): @soap(String,Integer,_returns=Array(String)) def say_hello(self,name,times): results = [] for i in range(0,times): results.append('Hello, %s'%name) return results class WsgiApp(wsgi.Application): def on_wsgi_return(self, env, headers, return_str): headers['Set-Cookie'] = 'spam=eggs;domain=127.0.0.1;path=/' print >>sys.stderr, headers if __name__=='__main__': try: from wsgiref.simple_server import make_server soap_application = soaplib.core.Application([HelloWorldService], 'tns') wsgi_application = WsgiApp(soap_application) server = make_server('localhost', 7789, wsgi_application) server.serve_forever() except ImportError: print "Error: example server code requires Python >= 2.5" 

with some slight modification to setting the cookie header.

and suds-testclient:

 from suds import client, transport c = client.Client("http://127.0.0.1:7789/?wsdl") print c.service.say_hello("spam", 1) print c.options.transport.cookiejar 

this is done:

 (stringArray){ string[] = "Hello, spam", } <cookielib.CookieJar[<Cookie spam=eggs for .127.0.0.1/>]> 

so he goes to work. but if you change the request URL to http://localhost:7789/?wsdl , you will get:

 (stringArray){ string[] = "Hello, spam", } <cookielib.CookieJar[]> 

enabling some logging for cookielib on the client ...

 import logging import cookielib logging.basicConfig() logging.getLogger('cookielib').setLevel(logging.DEBUG) cookielib.debug = True 

... and it shows why:

 DEBUG:cookielib:add_cookie_header DEBUG:cookielib:extract_cookies: Date: Thu, 17 May 2012 15:56:01 GMT Server: WSGIServer/0.1 Python/2.7.3 Set-Cookie: spam=eggs;domain=127.0.0.1;path=/ Content-Length: 822 Content-Type: text/xml DEBUG:cookielib: - checking cookie spam=eggs DEBUG:cookielib: effective request-host localhost.local (even with added initial dot) does not end with .127.0.0.1 (stringArray){ string[] = "Hello, spam", } <cookielib.CookieJar[]> 

simple explanation: the cookie domain does not match the domain of the request server, and it seems that cookielib does not perform a search when checking the domain.

so the solution will be one of:

  • make sure that the client and server use the same domain (domain name or IP)
    in this example, I have to set both parameters to localhost.local so that it works (may depend on the hosts ...)
  • delete the domain from the sent cookie, then cookieib automatically uses the request domain
  • implement cookiejar that uses DNS lookup

Oh, and last but not least, the reason he didn't work on the OPs question:
the port is not part of the domain, so a cookie with Domain=10.242.69.4:8088 will always be rejected.

+6
source

All Articles