Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过http POST上载gzip时出错_Python_Python 3.x_Gzip_Gzipstream_Httplib2 - Fatal编程技术网

Python 通过http POST上载gzip时出错

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.

因此,我正在尝试通过Python3.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文件时工作得很好,即通过提供
“Content Length”
头解决了
Content file

,这显然消除了httplib2检查长度的需要