gpt4 book ai didi

python - 使用 gzip 启用 KMZ 输出

转载 作者:太空宇宙 更新时间:2023-11-04 06:28:27 25 4
gpt4 key购买 nike

当我尝试为输出启用 gzip 时,出现以下错误:

Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 634, in __call__
handler.get(*groups)
File "/base/data/home/apps/my-app-ip/django2.349712625627523096/main.py", line 2246, in get
self.response.out.write(compressBuf(output))
File "/base/data/home/apps/my-app-ip/django2.349712625627523096/main.py", line 1618, in compressBuf
zfile.write(buf)
File "/base/python_runtime/python_dist/lib/python2.5/gzip.py", line 204, in write
self.crc = zlib.crc32(data, self.crc)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 1075: ordinal not in range(128)

我的代码是

def compressBuf(buf):
zbuf = StringIO.StringIO()
zfile = gzip.GzipFile(None, 'wb', 9, zbuf)
zfile.write(buf)
zfile.close()
return zbuf.getvalue()

你能告诉我我做错了什么吗?谢谢

最佳答案

看来您需要将编码设置为 utf-8。看这个question .

关于python - 使用 gzip 启用 KMZ 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5664414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com