使用gzip启用KMZ输出

问题描述

| 当我尝试为输出启用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。看到这个问题。     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...