gpt4 book ai didi

python - 如何将 BytesIO 对象附加到 Webob.Response 对象

转载 作者:太空宇宙 更新时间:2023-11-04 05:34:32 25 4
gpt4 key购买 nike

我正在从我的服务器向 http 请求返回一个 Webob.Response 对象。服务器将一个 BytesIO 对象放在一起。如何正确地将 BytesIO 对象附加到 Webob.Response 对象?

我试过:

app_iter = FileIter(BytesIO_Object)
return Response(
app_iter=app_iter,
last_modified=last_modified,
content_length=content_length,
content_type=content_type,
content_encoding=content_encoding,
content_disposition=content_disposition,
accept_ranges=accept_ranges,
conditional_response=True)

运气不好,当我在客户端打印 response.content 时,它只是空的

我也试过:

return Response(self.file, '200 ok', content_type='text/html')

但这会引发错误:

File "/home/abdul/abdul/scripting-120218/local/lib/python2.7/site-packages/webob/response.py", line 147, in init self._headerlist.append(('Content-Length', str(len(body)))) TypeError: object of type '_io.BytesIO' has no len()

最佳答案

好吧,终于明白了。您可以将其传递给 FileIter

app_iter = FileIter(BytesIO_Object.read())

关于python - 如何将 BytesIO 对象附加到 Webob.Response 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36043926/

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