좋아 파일 포함 된 파일을 다운로드, 난 있습니다. 다운로드 할 수있는 3 개의 개별 파일에 3 가지 코드 값을 저장하는 zip 파일을 어떻게 만들 수 있습니까? eric.f의 답변에 따라구글 앱 엔진이
:
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'+`content.key().id()`, code)
self.response.headers["Content-Type"] = "application/zip"
self.response.headers['Content-Disposition'] = "attachment; filename=test.zip"
self.response.out.write(output.getvalue())
그래도 난 오류가있어 ...
self.response.out.write(output.getvalue(), "utf-8")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/StringIO.py", line 270, in getvalue
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb4 in position 10: ordinal not in range(128)
코드에서 유니 코드를 사용하고 있습니까? zipfile에 쓰기 전에 모든 코드가 ascii인지 확인하는 것이 아니라 writestr()의 코드 대신 str (코드)을 사용하십시오. – Takahiro
코드에 사용자가 제출하는 python 코드가 들어 있습니다. – areke
보십시오 [this] (http://stackoverflow.com/questions/4542961/writing-unicode-to-binary-file-in-python) – Takahiro