python 协程下载文件
异步下载文件
async def download_file_with_curl(url: str, destination: str):
curl_command = [
"curl",
"-k",
f"{url}",
"-o",
destination,
]
process = await asyncio.create_subprocess_exec(
*curl_command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
logger.debug(stdout.decode().strip())
if process.returncode != 0:
logger.debug(stderr.decode().strip())
# print(stderr.decode().strip())
raise FileNotDownloadError(f"Curl download failed: {stderr.decode().strip()}")
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/18409559