diff --git a/src/clover_image/download_image.py b/src/clover_image/download_image.py index 3a8edb9..2eb2ca3 100644 --- a/src/clover_image/download_image.py +++ b/src/clover_image/download_image.py @@ -1,4 +1,4 @@ -import requests +import aiohttp async def download_image(url,file_path): """ @@ -8,10 +8,14 @@ async def download_image(url,file_path): :return: """ try: - response = requests.get(url, stream=True) - response.raise_for_status() - with open(file_path, 'wb') as file: - for chunk in response.iter_content(chunk_size=8192): - file.write(chunk) - except requests.RequestException as e: + async with aiohttp.ClientSession() as session: + async with session.get(url) as response: + response.raise_for_status() + with open(file_path, 'wb') as file: + while True: + chunk = await response.content.read(8192) + if not chunk: + break + file.write(chunk) + except aiohttp.ClientError as e: print(f"下载图片时出错: {e}") \ No newline at end of file