️ 修改 SSL 问题修复方式

This commit is contained in:
Asankilp 2025-03-23 22:58:10 +08:00
parent fce3152e17
commit e4490334fa

View File

@ -2,6 +2,7 @@ import base64
import json import json
import mimetypes import mimetypes
import re import re
import ssl
import uuid import uuid
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
@ -58,6 +59,8 @@ _praises_init_data = {
""" """
初始夸赞名单之数据 初始夸赞名单之数据
""" """
_ssl_context = ssl.create_default_context()
_ssl_context.set_ciphers("DEFAULT")
async def get_image_raw_and_type( async def get_image_raw_and_type(
@ -74,7 +77,7 @@ async def get_image_raw_and_type(
tuple[bytes, str]: 图片二进制数据, 图片MIME格式 tuple[bytes, str]: 图片二进制数据, 图片MIME格式
""" """
async with httpx.AsyncClient() as client: async with httpx.AsyncClient(verify=_ssl_context) as client:
response = await client.get(url, headers=_browser_headers, timeout=timeout) response = await client.get(url, headers=_browser_headers, timeout=timeout)
if response.status_code == 200: if response.status_code == 200:
# 获取图片数据 # 获取图片数据
@ -98,9 +101,7 @@ async def get_image_b64(url: str, timeout: int = 10) -> Optional[str]:
return: 图片base64编码 return: 图片base64编码
""" """
if data_type := await get_image_raw_and_type( if data_type := await get_image_raw_and_type(url, timeout):
url.replace("https://", "http://"), timeout
):
# image_format = content_type.split("/")[1] if content_type else "jpeg" # image_format = content_type.split("/")[1] if content_type else "jpeg"
base64_image = base64.b64encode(data_type[0]).decode("utf-8") base64_image = base64.b64encode(data_type[0]).decode("utf-8")
data_url = "data:{};base64,{}".format(data_type[1], base64_image) data_url = "data:{};base64,{}".format(data_type[1], base64_image)