Search code examples
pythonbase64zipbytewebservice-client

How to acccess a zip file stored in a bytes variable in Python 3?


I am writting a Python script that consumes a Web Service in order to access some xml file stored in a zipped folder with 3 other xml files: zipfolder/myxmlfile.xml

The Web Service provides a method "GetResponse" that can be used to get the zipped folder in the form of base64 data, as explained in the documentation.

So I use this method as the following:

response = client.service.GetResponse()
  • "response" if of class "bytes". Shouldn't it be base64 as described in the documentation?

  • How can I access my xml file using this variable which presumably contains the zip file data?

Your help is highly appreciated.


Solution

  • Try this using base64:

    import base64
    bin = base64.b64decode(response)
    with open('your_path/your_filename.zip', 'wb') as f:
        f.write(bin)