【发布时间】:2021-06-16 13:14:59
【问题描述】:
我想创建一个以 mp4 视频为内容的 http 响应
按照我找到的here 的建议,这就是我目前所拥有的:
resp = Response()
resp.status_code = 200
with open("unit_tests/unit_test_data/testvid 2 - public_2.mp4", "rb") as vid:
resp._content = vid.read(1024 * 1024)
resp.headers = {"content-length": "13837851"}
然后将按如下方式使用此响应:
with open(fname, "wb") as file:
for data in resp.iter_content(chunk_size=1024):
size = file.write(data)
但是在第二部分,当我尝试阅读我的回复内容时,我收到以下错误:
AttributeError: 'NoneType' object has no attribute 'read'
欢迎任何帮助,谢谢!
【问题讨论】:
标签: python request httprequest