DBFahrerKaterchen3 commited on
Commit
bbb6b8c
·
verified ·
1 Parent(s): 51ef008

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -50,11 +50,13 @@ async def oauth_callback(code: str = None):
50
  }
51
  headers = {"Content-Type": "application/x-www-form-urlencoded"}
52
 
53
- # Wir nutzen httpx mit deaktivierter SSL-Prüfung (verify=False), falls die Container-Zertifikate spinnen
54
- async with httpx.AsyncClient(verify=False) as client:
 
 
55
  try:
56
  # 1. Code gegen Token tauschen
57
- token_res = await client.post(token_url, data=data, headers=headers)
58
  token_data = token_res.json()
59
 
60
  if "access_token" not in token_data:
@@ -65,7 +67,7 @@ async def oauth_callback(code: str = None):
65
  # 2. Nutzerdaten holen
66
  user_res = await client.get("https://discord.com/api/v10/users/@me", headers={
67
  "Authorization": f"Bearer {access_token}"
68
- })
69
  user_json = user_res.json()
70
  username = user_json.get("username", "Nutzer")
71
 
@@ -82,7 +84,7 @@ async def oauth_callback(code: str = None):
82
  put_res = await client.put(connection_url, json=connection_body, headers={
83
  "Authorization": f"Bearer {access_token}",
84
  "Content-Type": "application/json"
85
- })
86
 
87
  if put_res.status_code == 200:
88
  return HTMLResponse(f"""
@@ -95,4 +97,11 @@ async def oauth_callback(code: str = None):
95
  return HTMLResponse(f"<h3 style='color:red;'>Metadaten-Fehler: {put_res.text}</h3>")
96
 
97
  except Exception as e:
98
- return HTMLResponse(f"<h3 style='color:red;'>Netzwerk-Fehler im Space-Backend: {str(e)}</h3>")
 
 
 
 
 
 
 
 
50
  }
51
  headers = {"Content-Type": "application/x-www-form-urlencoded"}
52
 
53
+ # Wir erstellen ein Transport-Objekt, das explizit IPv4 erzwingt (verhindert hängende Routen)
54
+ transport = httpx.AsyncHTTPTransport(local_address="0.0.0.0")
55
+
56
+ async with httpx.AsyncClient(verify=False, transport=transport) as client:
57
  try:
58
  # 1. Code gegen Token tauschen
59
+ token_res = await client.post(token_url, data=data, headers=headers, timeout=15.0)
60
  token_data = token_res.json()
61
 
62
  if "access_token" not in token_data:
 
67
  # 2. Nutzerdaten holen
68
  user_res = await client.get("https://discord.com/api/v10/users/@me", headers={
69
  "Authorization": f"Bearer {access_token}"
70
+ }, timeout=15.0)
71
  user_json = user_res.json()
72
  username = user_json.get("username", "Nutzer")
73
 
 
84
  put_res = await client.put(connection_url, json=connection_body, headers={
85
  "Authorization": f"Bearer {access_token}",
86
  "Content-Type": "application/json"
87
+ }, timeout=15.0)
88
 
89
  if put_res.status_code == 200:
90
  return HTMLResponse(f"""
 
97
  return HTMLResponse(f"<h3 style='color:red;'>Metadaten-Fehler: {put_res.text}</h3>")
98
 
99
  except Exception as e:
100
+ # Zeigt uns jetzt den exakten Systemfehler (z.B. Timeout oder ConnectionRefused)
101
+ return HTMLResponse(f"""
102
+ <body style="font-family: Arial; background-color: #23272A; color: white; padding: 20px;">
103
+ <h3 style="color: #ED4245;">Netzwerk-Fehler im Space-Backend:</h3>
104
+ <p><b>Details:</b> {type(e).__name__} - {str(e)}</p>
105
+ <p>Falls hier 'TimeoutException' steht, blockiert Hugging Face ausgehende API-Anrufe.</p>
106
+ </body>
107
+ """)