Skip to content

Commit 820f8f5

Browse files
authored
feat: fix SSL cert on desktop app (agentscope-ai#1252)
1 parent 47d0dcf commit 820f8f5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

scripts/pack/build_common.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ def main() -> int:
149149
f"copaw[full] @ {wheel_uri}",
150150
],
151151
)
152+
print("Verifying certifi is installed (required for SSL)...")
153+
_run(
154+
[
155+
conda,
156+
"run",
157+
"-n",
158+
env_name,
159+
"python",
160+
"-c",
161+
"import certifi; print(f'certifi OK: {certifi.where()}')",
162+
],
163+
)
152164
if args.cache_wheels:
153165
# Store outside dist/ to avoid being deleted by wheel_build cleanup
154166
wheels_cache = REPO_ROOT / ".cache" / "conda_unpack_wheels"

scripts/pack/build_macos.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,33 @@ LOG="$HOME/.copaw/desktop.log"
6464
unset PYTHONPATH
6565
export PYTHONHOME="$ENV_DIR"
6666
export COPAW_DESKTOP_APP=1
67+
68+
# Set SSL certificate paths for packaged environment
69+
# Query certifi path from the packaged Python interpreter
70+
if [ -x "$ENV_DIR/bin/python" ]; then
71+
CERT_FILE=$("$ENV_DIR/bin/python" -c \
72+
"import certifi; print(certifi.where())" 2>/dev/null)
73+
if [ -n "$CERT_FILE" ] && [ -f "$CERT_FILE" ]; then
74+
export SSL_CERT_FILE="$CERT_FILE"
75+
export REQUESTS_CA_BUNDLE="$CERT_FILE"
76+
export CURL_CA_BUNDLE="$CERT_FILE"
77+
fi
78+
fi
79+
6780
cd "$HOME" || true
6881
if [ ! -t 2 ]; then
6982
mkdir -p "$HOME/.copaw"
7083
{ echo "=== $(date) CoPaw starting ==="
7184
echo "ENV_DIR=$ENV_DIR"
7285
echo "Python: $ENV_DIR/bin/python (exists=$([ -x "$ENV_DIR/bin/python" ] && echo yes || echo no))"
86+
echo "SSL_CERT_FILE=${SSL_CERT_FILE:-not set}"
87+
if [ -n "$SSL_CERT_FILE" ] && [ -f "$SSL_CERT_FILE" ]; then
88+
echo "SSL certificate file found at $SSL_CERT_FILE"
89+
elif [ -n "$SSL_CERT_FILE" ]; then
90+
echo "WARNING: SSL_CERT_FILE set but file does not exist: $SSL_CERT_FILE"
91+
else
92+
echo "WARNING: SSL_CERT_FILE not set, SSL connections may fail"
93+
fi
7394
} >> "$LOG"
7495
exec 2>> "$LOG"
7596
exec 1>> "$LOG"

scripts/pack/build_win.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ $LauncherBat = Join-Path $EnvRoot "CoPaw Desktop.bat"
130130
@"
131131
@echo off
132132
cd /d "%~dp0"
133+
134+
REM Set SSL certificate paths for packaged environment
135+
REM Query certifi path from the packaged Python interpreter
136+
for /f "delims=" %%i in ('"%~dp0python.exe" -c "import certifi; print(certifi.where())" 2^>nul') do set "CERT_FILE=%%i"
137+
if defined CERT_FILE (
138+
if exist "%CERT_FILE%" (
139+
set "SSL_CERT_FILE=%CERT_FILE%"
140+
set "REQUESTS_CA_BUNDLE=%CERT_FILE%"
141+
set "CURL_CA_BUNDLE=%CERT_FILE%"
142+
)
143+
)
144+
133145
if not exist "%USERPROFILE%\.copaw\config.json" (
134146
"%~dp0python.exe" -m copaw init --defaults --accept-security
135147
)
@@ -141,11 +153,24 @@ $DebugBat = Join-Path $EnvRoot "CoPaw Desktop (Debug).bat"
141153
@"
142154
@echo off
143155
cd /d "%~dp0"
156+
157+
REM Set SSL certificate paths for packaged environment
158+
REM Query certifi path from the packaged Python interpreter
159+
for /f "delims=" %%i in ('"%~dp0python.exe" -c "import certifi; print(certifi.where())" 2^>nul') do set "CERT_FILE=%%i"
160+
if defined CERT_FILE (
161+
if exist "%CERT_FILE%" (
162+
set "SSL_CERT_FILE=%CERT_FILE%"
163+
set "REQUESTS_CA_BUNDLE=%CERT_FILE%"
164+
set "CURL_CA_BUNDLE=%CERT_FILE%"
165+
)
166+
)
167+
144168
echo ====================================
145169
echo CoPaw Desktop - Debug Mode
146170
echo ====================================
147171
echo Working Directory: %cd%
148172
echo Python: "%~dp0python.exe"
173+
echo SSL_CERT_FILE: %SSL_CERT_FILE%
149174
echo.
150175
if not exist "%USERPROFILE%\.copaw\config.json" (
151176
echo [Init] Creating config...

0 commit comments

Comments
 (0)