0

因此,我尝试在 Python 3.2 中通过 httplib2 发布一个压缩文件。我收到以下错误:

io.UnsupportedOperation: 文件号

我以前只发布一个 xml 文件,但由于这些文件变得太大,我想先将它们压缩到内存中。

这就是我在内存中创建压缩文件的方式:

contentfile = open(os.path.join(r'path', os.path.basename(fname)), 'rb')
tempfile = io.BytesIO()
compressedFile = gzip.GzipFile(fileobj=tempfile, mode='wb')
compressedFile.write(contentfile.read())
compressedFile.close()
tempfile.seek(0)

这就是我试图发布它的方式。

http.request(self.URL,'POST', tempfile, headers={"Content-Type": "application/x-gzip", "Connection": "keep-alive"})

有任何想法吗 ?

就像我说的,它在使用 xml 文件时运行良好,即contentfile

4

1 回答 1

0

通过提供"Content-Length"标头来解决,这显然消除了 httplib2 检查长度的需要。

于 2013-11-15T13:56:18.547 回答