在链接https://zetcode.com/python/httpx/中,它具有以下stream示例
import httpx
url = 'https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/12.0/FreeBSD-12.0-RELEASE-amd64-mini-memstick.img'
with open('FreeBSD-12.0-RELEASE-amd64-mini-memstick.img', 'wb') as f:
with httpx.stream('GET', url) as r:
for chunk in r.iter_bytes():
f.write(chunk)这是一种异步流式传输数据的方式吗?例如:
async def stream(call_back):
async with httpx.stream('GET', url) as r:
for chunk in await? r.iter_bytes():
await call_back(chunk)发布于 2021-11-24 23:42:55
这应该会起作用,
async def stream(cb):
async with httpx.AsyncClient() as client:
async with client.stream('GET', url) as resp:
async for chunk in resp.aiter_bytes():
await cb(chunk)问题是每个块都很小,比如3K字节。
https://stackoverflow.com/questions/70102869
复制相似问题