所以我有一个 StringIO()
类似文件的对象,我正在尝试将其写入 ZipFile()
,但我得到这个TypeError:
coercing to Unicode: need string or buffer, cStringIO.StringI found
以下是我正在使用的代码示例:
file_like = StringIO()
archive = zipfile.ZipFile(file_like, 'w', zipfile.ZIP_DEFLATED)
# my_file is a StringIO object returned by a remote file storage server.
archive.write(my_file)
文档说 StringIO()
是一个类似文件的类 ZipFile()
可以接受类似文件的对象。有什么我想念的吗?任何帮助将不胜感激。
提前致谢!