我正在使用適用於Python的Google App Engine,但遇到unicode錯誤,是否有解決此問題的方法? 這裏是我的代碼:任何人都知道如何解決unicode錯誤?
def get(self):
contents = db.GqlQuery("SELECT * FROM Content ORDER BY created DESC")
output = StringIO.StringIO()
with zipfile.ZipFile(output, 'w') as myzip:
for content in contents:
if content.code:
code=content.code
else:
code=content.code2
myzip.writestr("udacity_code", code)
self.response.headers["Content-Type"] = "application/zip"
self.response.headers['Content-Disposition'] = "attachment; filename=test.zip"
self.response.out.write(output.getvalue())
我現在得到一個Unicode錯誤:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf7 in position 12: ordinal not in range(128)
我相信它是從output.getvalue來()...是有辦法解決這一問題?
如果包含了完整的堆棧跟蹤,我們不會有猜測,發生錯誤 - 該堆棧跟蹤告訴你。 – 2012-07-24 07:15:36