我尝试在webob.Response中返回二进制,但出现错误
file = open(filePath, 'rb')
buffer = file.read()
file.close()
self._response.body = buffer给出回溯
"F:\Program Files\Python32\python.exe" G:/development/projects/AutoBlog/main.py
Traceback (most recent call last):
File "F:\Program Files\Python32\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "G:/development/projects/AutoBlog/main.py", line 30, in application
print(wsgiApplication)
File "F:\Program Files\Python32\lib\site-packages\webob\response.py", line 218, in __str__
parts += ['', self.text if PY3 else self.body]
File "F:\Program Files\Python32\lib\site-packages\webob\response.py", line 383, in _text__get
return body.decode(self.charset, self.unicode_errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
activate.adobe.com - - [20/May/2012 14:52:49] "GET /res/images/i.jpg HTTP/1.1" 500 59发布于 2012-05-20 19:07:52
看起来webob把你的身体当成了一个字符串,而它实际上是一个二进制对象。也许你需要设置内容类型?
https://stackoverflow.com/questions/10672796
复制相似问题