我正在尝试用烧瓶中的电报制作一个文件流媒体
我使用的代码
from flask import Response
@app.route("/dl/<hash>", methods=["GET"])
async def download(hash):
body = yield_file()
return Response(
status=206 if range_header else 200,
response=body,
headers={
"Content-Type": f"{mime_type}",
"Content-Range": f"bytes {from_bytes}-{until_bytes}/{file_size}",
"Content-Length": str(req_length),
"Content-Disposition": f'{disposition}; filename="{file_name}"',
"Accept-Ranges": "bytes",
},
)
获取yield_file()函数
在仓库中他使用了 aiohttp Web 服务器并且它在那里工作正常
但在烧瓶中它给出以下错误
127.0.0.1 - - [03/Aug/2023 22:21:06] "GET /dl/jRtYoKqEu6 HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Roaming\Python\Python310\site-packages\werkzeug\serving.py", line 364, in run_wsgi
execute(self.server.app)
File "C:\Users\hp\AppData\Roaming\Python\Python310\site-packages\werkzeug\serving.py", line 327, in execute
for data in application_iter:
File "C:\Users\hp\AppData\Roaming\Python\Python310\site-packages\werkzeug\wsgi.py", line 289, in __next__
return self._next()
File "C:\Users\hp\AppData\Roaming\Python\Python310\site-packages\werkzeug\wrappers\response.py", line 32, in _iter_encoded
for item in iterable:
TypeError: 'async_generator' object is not iterable
我可以知道这里有什么问题以及如何解决吗
编辑:
它使用
for
关键字而不是 async for
这应该有效:
import asyncstdlib
async for i, numbers in asyncstdlib.enumerate(gen_random_numbers()):
print(f"working with the batch {i} and processing {numbers}")