如何访问存储在 Python 3 中字节变量中的 zip 文件?

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

我正在编写一个使用 Web 服务的 Python 脚本,以便访问与其他 3 个 xml 文件一起存储在压缩文件夹中的某些 xml 文件:zipfolder/myxmlfile.xml

Web 服务提供了一种方法 "GetResponse",可用于获取 base64 数据形式的压缩文件夹,如文档中所述。

所以我使用这个方法如下:

response = client.service.GetResponse()

非常感谢您的帮助。

尝试使用 base64:

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

当我检查我的 "response" 数据时,我发现它不是 base64,所以我对它进行了 Base64 编码,然后我对它进行了 Base64 解码。最后,我写入了一个 zip 文件,它成功了。

encoded = base64.b64encode(response)
decoded = base64.b64decode(encoded)
with open('myzipfile.zip', 'wb') as f:
 f.write(decoded)