【发布时间】:2013-01-30 20:34:26
【问题描述】:
我有一个上传表单,它接受一个 zip 文件,并有一个方法可以解压缩并从中获取每个文件。从它的 md5 哈希中制作一个唯一的 id 并将它们存储在字典中;
dict[uid] = imagebinary
并返回它以便表单可以将它们存储到 ZODB 中。我不能像这样存储图像,因为这个错误会吐出来;
2013-01-31 08:59:59,061 ERROR [waitress][Dummy-5] Exception when serving /
Traceback (most recent call last):
File "/home/maverick/inigo/sources/devenv/lib/python2.7/site-packages/waitress-0.8.2-py2.7.egg/waitress/channel.py", line 329, in service
task.service()
File "/home/maverick/inigo/sources/devenv/lib/python2.7/site-packages/waitress-0.8.2-py2.7.egg/waitress/task.py", line 173, in service
self.execute()
File "/home/maverick/inigo/sources/devenv/lib/python2.7/site-packages/waitress-0.8.2-py2.7.egg/waitress/task.py", line 380, in execute
app_iter = self.channel.server.application(env, start_response)
File "/home/maverick/.buildout/eggs/pyramid-1.4-py2.7.egg/pyramid/router.py", line 251, in __call__
response = self.invoke_subrequest(request, use_tweens=True)
File "/home/maverick/.buildout/eggs/pyramid-1.4-py2.7.egg/pyramid/router.py", line 227, in invoke_subrequest
response = handle_request(request)
File "/home/maverick/inigo/sources/devenv/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 133, in toolbar_tween
body = tb.render_full(request).encode('utf-8', 'replace')
File "/home/maverick/inigo/sources/devenv/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/tbtools.py", line 240, in render_full
summary = self.render_summary(include_title=False, request=request)
File "/home/maverick/inigo/sources/devenv/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/tbtools.py", line 229, in render_summary
'description': description_wrapper % escape(self.exception),
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 114: ordinal not in range(128)
那么,我该怎么做呢?我几乎被困在这一点上。
【问题讨论】:
-
请包含完整回溯。
imagebinary是什么类型,uid是什么类型? ZODB 可以存储任何默认的python类型,所以这很可能不是 ZODB。 -
@MartijnPieters
uid是str和imagebinary是str这是从压缩文件中读取的,我认为这是导致问题的原因? -
该错误与ZODB无关;请包含更多的代码上下文;
'description': description_wrapper % escape(self.exception),在调试工具栏中失败,掩盖了真正的异常。 -
好吧,我现在知道为什么 UnicodeDecodeErrors,我一直在愚蠢地这样做,uid = imagebinary.read(),这是非常错误的,对吧?那么,一般来说,如何将图像正确存储在金字塔+zodb中?我希望能够在 root['images'][uid].image 处调用图像,并获取图像。