【问题标题】:Errow while uploading gzip via http POST通过 http POST 上传 gzip 时出错
【发布时间】:2013-11-15 09:30:09
【问题描述】:

所以我尝试在 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

【问题讨论】:

    标签: python python-3.x gzip gzipstream httplib2


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 2010-11-01
      • 2017-06-07
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      相关资源
      最近更新 更多