mirror of
https://github.com/Murasame-Dev/McStatus-Img.git
synced 2025-12-16 05:07:57 +00:00
Upgrade
This commit is contained in:
parent
5c576c811f
commit
57a741ca17
9 changed files with 199 additions and 18 deletions
26
get_background.py
Normal file
26
get_background.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import httpx
|
||||
|
||||
def download_image_with_httpx_auto_redirect(url:str):
|
||||
"""
|
||||
使用httpx库自动处理重定向下载图片
|
||||
|
||||
Args:
|
||||
url (str): 图片URL
|
||||
save_path (str): 保存路径
|
||||
"""
|
||||
try:
|
||||
# httpx默认也会自动跟随重定向
|
||||
with httpx.Client(follow_redirects=True) as client:
|
||||
response = client.get(url, timeout=30.0)
|
||||
|
||||
# 检查状态码
|
||||
if response.status_code == 200:
|
||||
Background = response.content
|
||||
return Background
|
||||
else:
|
||||
print(f"请求失败,状态码: {response.status_code}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"下载失败: {e}")
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue