Python 通过http POST上载gzip时出错
因此,我正在尝试通过Python3.2中的httplib2发布一个压缩文件。我得到以下错误: io.UnsupportedOperation:文件号 我过去只发布一个xml文件,但由于这些文件太大,我想先将它们压缩到内存中 以下是我在内存中创建压缩文件的方式:Python 通过http POST上载gzip时出错,python,python-3.x,gzip,gzipstream,httplib2,Python,Python 3.x,Gzip,Gzipstream,Httplib2,因此,我正在尝试通过Python3.2中的httplib2发布一个压缩文件。我得到以下错误: io.UnsupportedOperation:文件号 我过去只发布一个xml文件,但由于这些文件太大,我想先将它们压缩到内存中 以下是我在内存中创建压缩文件的方式: contentfile = open(os.path.join(r'path', os.path.basename(fname)), 'rb') tempfile = io.BytesIO() compressedFile = gzip.
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文件时工作得很好,即通过提供
“Content Length”
头解决了Content file,这显然消除了httplib2检查长度的需要