fix: configure certifi CA before core imports

This commit is contained in:
邹永赫
2026-02-10 08:04:38 +09:00
parent b57312ac4b
commit 1702ef25e2

35
main.py
View File

@@ -5,10 +5,25 @@ import os
import sys
from pathlib import Path
from astrbot.core import LogBroker, LogManager, db_helper, logger
from astrbot.core.config.default import VERSION
from astrbot.core.initial_loader import InitialLoader
from astrbot.core.utils.astrbot_path import (
def _configure_runtime_ca_bundle() -> None:
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:
return
_configure_runtime_ca_bundle()
from astrbot.core import LogBroker, LogManager, db_helper, logger # noqa: E402, I001
from astrbot.core.config.default import VERSION # noqa: E402
from astrbot.core.initial_loader import InitialLoader # noqa: E402
from astrbot.core.utils.astrbot_path import ( # noqa: E402
get_astrbot_config_path,
get_astrbot_data_path,
get_astrbot_plugin_path,
@@ -16,7 +31,7 @@ from astrbot.core.utils.astrbot_path import (
get_astrbot_site_packages_path,
get_astrbot_temp_path,
)
from astrbot.core.utils.io import download_dashboard, get_dashboard_version
from astrbot.core.utils.io import download_dashboard, get_dashboard_version # noqa: E402
# 将父目录添加到 sys.path
sys.path.append(Path(__file__).parent.as_posix())
@@ -50,16 +65,6 @@ 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")