2013-11-15 44 views
0

因此,我试着通过Python 3.2中的httplib2发布一个压缩文件。我得到以下错误:通过http POST上载gzip时发生错误

io.UnsupportedOperation: fileno

我用来张贴只是一个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

回答

0

通过提供"Content-Length"头这显然消除了需要对httplib2的查询的长度解决时运行良好。