gpt4 book ai didi

python - 通过webob.Response返回二进制数据

转载 作者:太空宇宙 更新时间:2023-11-03 19:18:09 25 4
gpt4 key购买 nike

我尝试在 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

最佳答案

看起来webob将你的body视为一个字符串,但它实际上是一个二进制对象。也许您需要设置内容类型?

关于python - 通过webob.Response返回二进制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10672796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com