如果使用gzip、compress或deflate压缩主体或HTTP响应,则使用此函数来解压缩该主体或HTTP响应。
def uncompress_body(self, compression_type, body):
if compression_type == 'gzip' or compression_type == 'compress':
return zlib.decompress(body)
elif compression_type == 'deflate':
compressor = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS)
compressed = compressor.compress(body)
compressed += compressor.flush()
return base64.b64encode(compressed)
return body
但是,python会抛出此错误消息。
TypeError: a bytes-like object is required, not '_io.BytesIO'
在这一行上:
return zlib.decompress(body)
从本质上讲,我如何从“字节集”转换为类似对象的字节?
谢谢