Enabling KMZ output with gzip
When I try enable gzip for an output the following error appears:
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)
The code I have is
def compressBuf(buf):
zbuf = StringIO.StringIO()
zfile = gzip.GzipFile(None, 'wb', 9, zbuf)
zfile.write(buf)
zfile.close()
return zbuf.getvalue()
Can you tell me what I'm doing wrong? Thank you
It looks like you need to set encoding to utf-8. See this question.
精彩评论