fix: aiohttp.client_exceptions.ClientPayloadError: Response payload is not completed

This commit is contained in:
2023-01-18 11:45:40 +07:00
parent 95dccf7241
commit f46902879a
2 changed files with 3 additions and 2 deletions

View File

@ -36,13 +36,14 @@ async def _download_file(file_url: str, file_name: str, file_path: Path | str, f
else:
await file_path.touch()
print(f"Downloading {file_url} to {file_path}...")
async with aiohttp.ClientSession() as session:
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=60*60, sock_read=240)) as session:
rsp = await session.get(file_url, headers=headers, timeout=None)
if rsp.status == 416:
return
rsp.raise_for_status()
while True:
chunk = await rsp.content.read(chunks)
await asyncio.sleep(0)
if not chunk:
break
async with file_path.open("ab") as f: