mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 17:47:06 +08:00
fix: use certifi CA bundle for runtime SSL requests
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import ssl
|
||||
from typing import Literal, TypedDict
|
||||
|
||||
import aiohttp
|
||||
import certifi
|
||||
|
||||
from astrbot.core import logger
|
||||
|
||||
@@ -32,7 +34,11 @@ LLM_METADATAS: dict[str, LLMMetadata] = {}
|
||||
async def update_llm_metadata() -> None:
|
||||
url = "https://models.dev/api.json"
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where())
|
||||
connector = aiohttp.TCPConnector(ssl=ssl_context)
|
||||
async with aiohttp.ClientSession(
|
||||
trust_env=True, connector=connector
|
||||
) as session:
|
||||
async with session.get(url) as response:
|
||||
data = await response.json()
|
||||
global LLM_METADATAS
|
||||
|
||||
@@ -39,7 +39,12 @@ class NetworkRenderStrategy(RenderStrategy):
|
||||
async def get_official_endpoints(self) -> None:
|
||||
"""获取官方的 t2i 端点列表。"""
|
||||
try:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where())
|
||||
connector = aiohttp.TCPConnector(ssl=ssl_context)
|
||||
async with aiohttp.ClientSession(
|
||||
trust_env=True,
|
||||
connector=connector,
|
||||
) as session:
|
||||
async with session.get(
|
||||
"https://api.soulter.top/astrbot/t2i-endpoints",
|
||||
) as resp:
|
||||
|
||||
10
main.py
10
main.py
@@ -50,6 +50,16 @@ def check_env() -> None:
|
||||
os.makedirs(get_astrbot_temp_path(), exist_ok=True)
|
||||
os.makedirs(site_packages_path, exist_ok=True)
|
||||
|
||||
try:
|
||||
import certifi
|
||||
|
||||
certifi_cafile = certifi.where()
|
||||
if certifi_cafile and os.path.exists(certifi_cafile):
|
||||
os.environ.setdefault("SSL_CERT_FILE", certifi_cafile)
|
||||
os.environ.setdefault("REQUESTS_CA_BUNDLE", certifi_cafile)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to configure certifi CA bundle: {e}")
|
||||
|
||||
# 针对问题 #181 的临时解决方案
|
||||
mimetypes.add_type("text/javascript", ".js")
|
||||
mimetypes.add_type("text/javascript", ".mjs")
|
||||
|
||||
Reference in New Issue
Block a user