mirror of
https://github.com/Murasame-Dev/McStatus-Img.git
synced 2025-12-16 05:07:57 +00:00
refactor to async
This commit is contained in:
parent
c8232f76bc
commit
d231980883
3 changed files with 31 additions and 14 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import httpx
|
||||
|
||||
def download_image_with_httpx_auto_redirect(url:str):
|
||||
async def download_image_with_httpx_auto_redirect(url:str):
|
||||
"""
|
||||
使用httpx库自动处理重定向下载图片
|
||||
|
||||
|
|
@ -10,9 +10,9 @@ def download_image_with_httpx_auto_redirect(url:str):
|
|||
"""
|
||||
try:
|
||||
# httpx默认也会自动跟随重定向
|
||||
with httpx.Client(follow_redirects=True) as client:
|
||||
response = client.get(url, timeout=30.0)
|
||||
|
||||
async with httpx.AsyncClient(follow_redirects=True) as client:
|
||||
response = await client.get(url, timeout=30.0)
|
||||
|
||||
# 检查状态码
|
||||
if response.status_code == 200:
|
||||
Background = response.content
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue