我正在尝试使用 zlib 在 python 3.6.3 中压缩一个字符串,但是得到一个错误(TypeError: a bytes-like object is required, not 'str') ,它应该在 python 2.7- 版本上工作,这是我的简单代码:
import zlib
a='hellohellohelloheeloohegregrf'
b=zlib.compress(a)
print(b)
Run Code Online (Sandbox Code Playgroud)