mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.89k stars 586 forks source link

Missing support for SOAP attachments #301

Closed isidrov closed 7 years ago

isidrov commented 7 years ago

Hi,

Version: zeep==0.24.0

WSDL: https://gist.github.com/isidrov/4016ff1baee7b879df200d50908880ce

sample script: https://gist.github.com/isidrov/d8b8bbf7993921f47d0e88d2450525ae

This method downloads a file as MIME. When enabling logging I can see the request going through, 200 response and through logging the content of the file, however, presumably before the full file is read the below error appears:

Traceback (most recent call last): File "/Users//PycharmProjects/Sparkify/toDelete.py", line 26, in FileContent = dime_client.service.GetOneFile('/var/log/active/syslog/AlternateSyslog') File "/usr/local/lib/python3.5/site-packages/zeep/client.py", line 41, in call self._op_name, args, kwargs) File "/usr/local/lib/python3.5/site-packages/zeep/wsdl/bindings/soap.py", line 113, in send return self.process_reply(client, operation_obj, response) File "/usr/local/lib/python3.5/site-packages/zeep/wsdl/bindings/soap.py", line 132, in process_reply doc = parse_xml(response.content, recover=True) File "/usr/local/lib/python3.5/site-packages/zeep/parser.py", line 13, in parse_xml return fromstring(content, parser=parser, base_url=base_url) File "/usr/local/lib/python3.5/site-packages/defusedxml/lxml.py", line 141, in fromstring elementtree = rootelement.getroottree() AttributeError: 'NoneType' object has no attribute 'getroottree'

The same request through SOAPUI works and I can download the file of 3.9 MB

Request through SOAPUI looks like the below:

/var/log/active/syslog/AlternateSyslog **Request through Zeep below:** zeep.transports: HTTP Post to https://IP ADDRESS/logcollectionservice/services/DimeGetFileService: /var/log/active/syslog/AlternateSyslog **Response in Zeep below:** zeep.transports: HTTP Response from https://IP ADDRESS/logcollectionservice/services/DimeGetFileService (status: 200): **The script Errors when creating the request returns** b'\n \n \n /var/log/active/syslog/AlternateSyslog\n \n \n\n' **The script when parsing the response returns** None Thank you!
isidrov commented 7 years ago

Does Zeep support Multipart responses? It does seem the response is not categorized as MIME

dwapstra commented 7 years ago

I have added multipart response support via https://github.com/mvantellingen/python-zeep/pull/302

mvantellingen commented 7 years ago

@isidrov could you give the master branch a try? Should be supported now

isidrov commented 7 years ago

Hello mvantellingen,

I might be doing something wrong, I will check again tomorrow but below are my observations

With #302 , after calling the Soap method I was retrieving the file in bytes as

pack = dime_client.service.GetOneFile('/var/log/active/log') pack = pack[1].content

It would save it locally no matter the extension

https://dl.dropboxusercontent.com/u/39392000/debug_%23302_attachment.png

Now with the latest code to get the same bytes I need:

pack = pack.attachments[0]._part.content

https://dl.dropboxusercontent.com/u/39392000/debug_0.27_attachment.png

I am guessing it is not intended to be there however attachments.data (BytesIO object) seems empty

Also I could only make it work with log files and not with gzip files, which I get the below:

header: X-Frame-Options header: Set-Cookie header: Content-Type header: Transfer-Encoding header: Date header: Server Traceback (most recent call last): File "/Users//PycharmProjects/cola/zeepVLC.py", line 302, in gzipFileContent = dime_client.service.GetOneFile('/var/log/active/cm/trace/ccm/sdl/SDL001_100_001151.txt.gz') File "/usr/local/lib/python3.5/site-packages/zeep/client.py", line 35, in call self._op_name, args, kwargs) File "/usr/local/lib/python3.5/site-packages/zeep/wsdl/bindings/soap.py", line 112, in send options['address'], envelope, http_headers) File "/usr/local/lib/python3.5/site-packages/zeep/transports.py", line 90, in post_xml return self.post(address, message, headers) File "/usr/local/lib/python3.5/site-packages/zeep/transports.py", line 73, in post log_message = log_message.decode('utf-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 875: invalid start byte

Thanks

mvantellingen commented 7 years ago

Should be fixed in master.

isidrov commented 7 years ago

It works nicely thanks! Tested both; text files and gzip. One thing I noticed is to access directly to the attachment through 'attachments' list, e.g. pack.attachments[0] - data attribute is not there or needed. If this is the intention I think is perfect although the data portion is still described in the documentation.

mvantellingen commented 7 years ago

Ah yeah, it's pack.attachments[0].content now. I'll update the docs. See https://github.com/mvantellingen/python-zeep/blob/master/src/zeep/wsdl/attachments.py for the interface