Spaces:
Sleeping
Sleeping
Make YouTube reachability check self-diagnosing: retry 3x, surface real SSL error, classify cert-trust vs reset
Browse files
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 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|