Closed Kilavagora closed 8 years ago
Oke, so handling subtypes was not implemented correctly (RecordRef is a subtype of BaseRef). This should be fixed now.
You also may need to add the soap header (pass _soapheader
to the method as kwarg)
Awesome! It worked. Thank you :) But I believe headers should be optional here, they shouldn’t be included unless you specify them explicitly. It does not work if you skip the header.
See 6ed076a2f15de4c511df67c106f3d5ac9d7d537c
Works without headers! For the service above, you either need to specify authentication information in SOAP header for each request, or authenticate and use the session. So I had to modify Transport to make it work with sessions:
class Transport(object):
def __init__(self, cache=None, timeout=300, verify=True, http_auth=None, session=False, cookies=None):
self.cache = cache or SqliteCache()
self.timeout = timeout
self.verify = verify
self.http_auth = http_auth
self.r=requests.Session() if session else requests
self.cookies=cookies
def load(self, url):
if self.cache:
response = self.cache.get(url)
if response:
return bytes(response)
response = self.r.get(url, timeout=self.timeout, verify=self.verify,
auth=self.http_auth, cookies=self.cookies)
if self.cache:
self.cache.add(url, response.content)
return response.content
def post(self, address, message, headers):
response = self.r.post(
address, data=message, headers=headers, verify=self.verify,
auth=self.http_auth, cookies=self.cookies
)
return response
def get(self, address, params, headers):
response = self.r.get(
address, params=params, headers=headers, verify=self.verify,
auth=self.http_auth,
cookies=self.cookies
)
return response
Seems like something we should offer by default in zeep. Is there a reason you didn't simply choose for a use_cookies=True/False kwag in the __init__
method?
I don't know whether I have a valid reason, but from what I understood from this, manually set cookies do not persist and they are kept separately from the session.
BTW, rather than adding parameters, wouldn't it be preferable to pass all the rest directly to requests kwargs without manually specifying the parameters? E.g. if there is a service that requires custom HTTP headers, or custom GET parameters, right now there is no direct way to pass these.
I've update the transport class. It should be easier to customize now by subclassing it and override the create_session() method.
Regarding the cookies. Do you set custom cookies based on pre-defined values?
I don't. Just session works fine for me :) But I need to pass custom HTTP headers eventually.
P.S. BTW, transport = Transport(cache=None) does not seem to disable caching.
Was thinking more about this. I think it is currently pretty easy to either create a custom transport class (subclass) or set transport.session.proxies = xx
. So i'm closing it for now
The following:
gives this error:
Here is the posted payload. It's missing the type specification and the attributes:
Below is the payload generated from C# client that works and gives the correct response:
P.S. Thanks for fixing the previous issue :)