Ein einfacher Trick, um die 5-fache Verbindungsunterbrechung von Codex Desktop zu beheben

@jinglian
CHINESISCHvor 1 Monat · 06. Juni 2026
500K
883
151
54
2.2K

TL;DR

Dieser Artikel erklärt, wie Sie das WebSocket-Handshake-Timeout von Codex Desktop beheben, indem Sie die HTTP- und HTTPS-Proxy-Umgebungsvariablen in der Konfigurationsdatei der Anwendung korrekt einstellen.

前端哥Liam - inline image

2:59

Wenn du Codex Desktop verwendest, begegnet dir wahrscheinlich oft folgende Situation:

前端哥Liam - inline image

Fast jedes Mal kommt erst nach 5 Wiederverbindungsversuchen eine Antwort. Diese 5 Wiederverbindungen lassen alle zu lange warten und sind glatte Zeitverschwendung.

Der Grund ist, dass nach der Aktualisierung auf eine neue Version von Codex Desktop (die genaue Version ist unbekannt) die Standardverbindungsmethode auf das WebSocket-Protokoll geändert wurde. Wenn diese Verbindung fehlschlägt, wird in den Logs direkt ein WebSocket-Handshake-Timeout angezeigt.

Warum passiert das? Weil Codex Desktop eine Desktop-Anwendung ist, die Systemproxys nicht automatisch wie ein Browser übernimmt. Beim Start muss sie explizit Umgebungsvariablen wie HTTP_PROXY und HTTPS_PROXY auslesen, um einen Proxy zu verwenden. Wenn diese Variablen nicht gesetzt sind, nimmt sie an, dass eine direkte Verbindung möglich ist, was zu langer Reaktionslosigkeit und einer Wiederverbindungsschleife führt.

macOS als Beispiel

  1. Gib den folgenden Befehl im Terminal ein, um die Proxy-Informationen anzuzeigen:
text
1scutil --proxy
前端哥Liam - inline image

Das obige Bild zeigt, dass die Proxy-Ports für http und https beide 6152 sind. Du kannst manuell die vorhandene Datei ~/.codex/.env erstellen oder bearbeiten und die Proxy-Variablen eintragen.

text
1HTTP_PROXY=http://127.0.0.1:6152
2HTTPS_PROXY=http://127.0.0.1:6152

Nachdem du ~/.codex/.env bearbeitet und gespeichert hast, beende Codex Desktop und öffne es erneut, um das Problem zu beheben.

Wenn du es nicht manuell machen möchtest, kannst du den folgenden Prompt verwenden und an Codex senden:

text
1Hilf mir, das Problem zu beheben, dass Codex Desktop ständig versucht, sich neu zu verbinden.
2
3Bitte ermittle den Proxy-Port und das aktuell verwendete Proxy-Protokoll auf meinem Rechner, erstelle oder aktualisiere dann ~/.codex/.env und trage folgende Proxy-Konfiguration ein. Verwende keinen fest codierten Port; ersetze ihn durch den tatsächlichen Port. Wenn die Datei bereits existiert, behalte andere Konfigurationen bei.
4
5HTTP_PROXY="http://127.0.0.1:<HTTP or mixed port>"
6HTTPS_PROXY="http://127.0.0.1:<HTTP or mixed port>"
7
8Überprüfe nach dem Schreiben, ob die Konfiguration korrekt ist, und sag mir, wie ich Codex Desktop neu starten muss.

Natürlich kannst du auch mein Ein-Klick-Automatisierungsskript ausprobieren (nur macOS):

bash
1#!/bin/bash
2# Detect macOS system proxy and update ~/.codex/.env
3
4ENV_DIR="$HOME/.codex"
5ENV_FILE="$ENV_DIR/.env"
6
7# Read system proxy configuration
8proxy_info=$(scutil --proxy)
9
10http_enabled=$(echo "$proxy_info" | awk '/HTTPEnable/{print $3}')
11http_host=$(echo "$proxy_info" | awk '/HTTPProxy/{print $3}')
12http_port=$(echo "$proxy_info" | awk '/HTTPPort/{print $3}')
13
14https_enabled=$(echo "$proxy_info" | awk '/HTTPSEnable/{print $3}')
15https_host=$(echo "$proxy_info" | awk '/HTTPSProxy/{print $3}')
16https_port=$(echo "$proxy_info" | awk '/HTTPSPort/{print $3}')
17
18# Build proxy URLs
19http_proxy=""
20https_proxy=""
21
22if [[ "$http_enabled" == "1" && -n "$http_host" && -n "$http_port" ]]; then
23 http_proxy="http://${http_host}:${http_port}"
24fi
25
26if [[ "$https_enabled" == "1" && -n "$https_host" && -n "$https_port" ]]; then
27 https_proxy="http://${https_host}:${https_port}"
28fi
29
30# If neither HTTP nor HTTPS proxy is found
31if [[ -z "$http_proxy" && -z "$https_proxy" ]]; then
32 echo "❌ No system proxy detected; no proxy settings applied."
33 exit 0
34fi
35
36# If HTTPS is not set separately, reuse HTTP proxy
37if [[ -n "$http_proxy" && -z "$https_proxy" ]]; then
38 https_proxy="$http_proxy"
39fi
40
41echo "✅ System proxy detected:"
42[[ -n "$http_proxy" ]] && echo " HTTP_PROXY=$http_proxy"
43[[ -n "$https_proxy" ]] && echo " HTTPS_PROXY=$https_proxy"
44
45# Ensure directory exists
46mkdir -p "$ENV_DIR"
47
48# If .env file doesn't exist, create it
49if [[ ! -f "$ENV_FILE" ]]; then
50 {
51 [[ -n "$http_proxy" ]] && echo "HTTP_PROXY=$http_proxy"
52 [[ -n "$https_proxy" ]] && echo "HTTPS_PROXY=$https_proxy"
53 } > "$ENV_FILE"
54 echo "📄 Created $ENV_FILE and wrote proxy configuration."
55 exit 0
56fi
57
58# File exists, update or append
59update_or_append() {
60 local key="$1" value="$2"
61 if grep -q "^${key}=" "$ENV_FILE"; then
62 sed -i '' "s|^${key}=.*|${key}=${value}|" "$ENV_FILE"
63 echo "🔄 Updated ${key}"
64 else
65 echo "${key}=${value}" >> "$ENV_FILE"
66 echo "➕ Appended ${key}"
67 fi
68}
69
70[[ -n "$http_proxy" ]] && update_or_append "HTTP_PROXY" "$http_proxy"
71[[ -n "$https_proxy" ]] && update_or_append "HTTPS_PROXY" "$https_proxy"
72
73echo "✅ $ENV_FILE update complete."

Möchtest du schnell mit KI starten, weißt aber nicht, wo du anfangen sollst?

AI Spark hat eine kostenlose KI-Wissensdatenbank zusammengestellt, die KI-Grundlagen, Wissensdatenbankaufbau, Workflow-Anwendungen, gängige KI-Tools, Obsidian, Codex, Skill und Prompt-Praxis abdeckt.

Kostenlose Wissensdatenbank:

https://lcnniolukk80.feishu.cn/wiki/space/7644091204958866380?ccm_open_type=lark_wiki_spaceLink&open_tab_from=wiki_home

Mit einem Klick speichern

Virale Artikel mit YouMind per KI tief lesen

Speichere die Quelle, stelle gezielte Fragen, fasse die Argumentation zusammen und verwandle einen viralen Artikel in wiederverwendbare Notizen in einem einzigen KI-Arbeitsbereich.

YouMind entdecken
Für Creator

Verwandle dein Markdown in einen sauberen 𝕏-Artikel

Wenn du eigene Langtexte veröffentlichst, wird die 𝕏-Formatierung von Bildern, Tabellen und Codeblöcken mühsam. YouMind macht aus einem ganzen Markdown-Entwurf einen sauberen, sofort postbaren 𝕏-Artikel.

Markdown zu 𝕏 testen

Mehr Muster zum Entschlüsseln

Aktuelle virale Artikel

Mehr virale Artikel entdecken