Python 使用POST将zlib压缩数据发送到服务器

Python 使用POST将zlib压缩数据发送到服务器,python,python-2.7,zlib,Python,Python 2.7,Zlib,我想使用POST请求将文件的zlib压缩数据发送到服务器。下面是我试图使用的代码 orig = open('fileName', 'r').read() comp = zlib.compress(orig, 9) req = Request(url, comp) urlopen(req) 但是我得到了以下错误:UnicodeDecodeError:“utf8”编解码器无法解码位置2的字节0x85:无效的开始字节 我尝试了以下comp.encode('utf-8'),但这也不起作用。我在某些位

我想使用POST请求将文件的zlib压缩数据发送到服务器。下面是我试图使用的代码

orig = open('fileName', 'r').read()
comp = zlib.compress(orig, 9)

req = Request(url, comp)
urlopen(req)
但是我得到了以下错误:UnicodeDecodeError:“utf8”编解码器无法解码位置2的字节0x85:无效的开始字节

我尝试了以下
comp.encode('utf-8')
,但这也不起作用。我在某些位置得到相同的
UnicodeDecodeError
。如何解决我的问题?

的文档的
数据
参数状态:

数据应为标准应用程序/x-www-form-urlencoded格式的缓冲区

您可以使用以下方法对缓冲区进行编码:

>>> orig = 'aaaaabbbccddxddaaabb'
>>> comp = zlib.compress(orig, 9)
>>> comp
'x\xdaKL\x04\x82\xa4\xa4\xa4\xe4\xe4\x94\x94\x8a\x94\x140\x07\x00Q\x19\x07\xc1'
>>> quoted = quote(comp)
>>> quoted
'x%DAKL%04%82%A4%A4%A4%E4%E4%94%94%8A%94%140%07%00Q%19%07%C1'
>>> req = Request('http://example.com', quoted)