From 243f45c7db3e51e42ee8223d198551cde7fe72f8 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Tue, 24 Dec 2024 11:09:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20header=20=E9=81=BF?= =?UTF-8?q?=E5=85=8D400?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/utils/image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/utils/image.py b/pkg/utils/image.py index 39d0dcec..72c63ef5 100644 --- a/pkg/utils/image.py +++ b/pkg/utils/image.py @@ -18,10 +18,14 @@ def get_qq_image_downloadable_url(image_url: str) -> tuple[str, dict]: async def get_qq_image_bytes(image_url: str) -> tuple[bytes, str]: """[弃用]获取QQ图片的bytes""" image_url, query = get_qq_image_downloadable_url(image_url) + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36', + 'Referer': 'https://multimedia.nt.qq.com.cn/' + } ssl_context = ssl.create_default_context() ssl_context.check_hostname = False ssl_context.verify_mode = ssl.CERT_NONE - async with aiohttp.ClientSession(trust_env=False) as session: + async with aiohttp.ClientSession(trust_env=False, headers=headers) as session: async with session.get(image_url, params=query, ssl=ssl_context) as resp: resp.raise_for_status() file_bytes = await resp.read()