vivekchakraverty commited on
Commit
38755c0
Β·
verified Β·
1 Parent(s): 439e009

Make YouTube reachability check self-diagnosing: retry 3x, surface real SSL error, classify cert-trust vs reset

Browse files
Files changed (1) hide show
  1. app.py +33 -10
app.py CHANGED
@@ -17,6 +17,7 @@ import os
17
  import re
18
  import shutil
19
  import tempfile
 
20
 
21
  import gradio as gr
22
 
@@ -104,16 +105,38 @@ def check_access():
104
  lines.append(f"- **Egress IP** {'(via proxy)' if proxy else '(Space direct)'}: `{ip}`")
105
  except Exception as exc:
106
  lines.append(f"- **Egress IP**: ❌ {type(exc).__name__}")
107
- try:
108
- r = requests.get("https://www.youtube.com/robots.txt", proxies=proxies, timeout=20)
109
- lines.append(f"- **YouTube reachable**: βœ… HTTP {r.status_code}")
110
- verdict = "### 🟒 YouTube is reachable β€” transcript + screenshots should work."
111
- except Exception as exc:
112
- lines.append(f"- **YouTube reachable**: ❌ {type(exc).__name__} (datacenter IP likely blocked)")
113
- verdict = ("### πŸ”΄ YouTube is NOT reachable from the Space.\n"
114
- "Set a residential **`YT_PROXY`** (e.g. the home-tunnel panel in "
115
- "[`tools/`](tools/README.md)). Comments still work via the Data API; "
116
- "transcript + screenshots need the proxy.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  return verdict + "\n\n" + "\n".join(lines)
118
 
119
 
 
17
  import re
18
  import shutil
19
  import tempfile
20
+ import time
21
 
22
  import gradio as gr
23
 
 
105
  lines.append(f"- **Egress IP** {'(via proxy)' if proxy else '(Space direct)'}: `{ip}`")
106
  except Exception as exc:
107
  lines.append(f"- **Egress IP**: ❌ {type(exc).__name__}")
108
+ yt = "https://www.youtube.com/robots.txt"
109
+ last = None
110
+ for attempt in range(3): # tolerate a transient TLS reset from the exit IP
111
+ try:
112
+ r = requests.get(yt, proxies=proxies, timeout=20)
113
+ lines.append(f"- **YouTube reachable**: βœ… HTTP {r.status_code}"
114
+ + (f" (after {attempt + 1} tries)" if attempt else ""))
115
+ verdict = "### 🟒 YouTube is reachable β€” transcript + screenshots should work."
116
+ return verdict + "\n\n" + "\n".join(lines)
117
+ except Exception as exc:
118
+ last = exc
119
+ time.sleep(1.5)
120
+ # All retries failed β€” classify: CA-trust failure vs connection/handshake reset.
121
+ detail = f"`{type(last).__name__}: {str(last)[:160]}`"
122
+ if isinstance(last, requests.exceptions.SSLError):
123
+ try:
124
+ import urllib3
125
+ urllib3.disable_warnings()
126
+ r = requests.get(yt, proxies=proxies, timeout=20, verify=False)
127
+ lines.append(f"- **YouTube reachable**: ⚠️ only with TLS verify OFF (HTTP "
128
+ f"{r.status_code}) β†’ stale CA bundle. {detail}")
129
+ verdict = ("### 🟠 YouTube reachable, but the Space can't verify its certificate.\n"
130
+ "Bump **`certifi`** in requirements.txt and rebuild the Space.")
131
+ return verdict + "\n\n" + "\n".join(lines)
132
+ except Exception as exc2:
133
+ detail = (f"verify-on: `{type(last).__name__}: {str(last)[:110]}` Β· "
134
+ f"verify-off: `{type(exc2).__name__}: {str(exc2)[:110]}`")
135
+ lines.append(f"- **YouTube reachable**: ❌ {detail}")
136
+ verdict = ("### πŸ”΄ YouTube is NOT reachable from the Space.\n"
137
+ "The proxy connects but YouTube's TLS is failing/reset (often the exit IP being "
138
+ "rate-limited β€” try again in a minute). If it persists, set/refresh a residential "
139
+ "**`YT_PROXY`** via the home-tunnel panel in [`tools/`](tools/README.md).")
140
  return verdict + "\n\n" + "\n".join(lines)
141
 
142