2

出力の 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()

私が間違っていることを教えてもらえますか?ありがとうございました

4

1 に答える 1

1

エンコーディングをutf-8に設定する必要があるようです。この質問を参照してください。

于 2011-04-14T14:19:55.123 に答える