【问题标题】:Enabling KMZ output with gzip使用 gzip 启用 KMZ 输出
【发布时间】:2011-04-14 14:01:36
【问题描述】:

当我尝试为输出启用 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()

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

【问题讨论】:

    标签: python google-app-engine unicode character-encoding kmz


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-21
      • 2018-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      • 2017-02-08
      • 2023-03-18
      相关资源
      最近更新 更多