Spaces:
Sleeping
Sleeping
Codex commited on
Commit ·
f773ac9
1
Parent(s): 494d4ff
Handle wrapped YouTube SSL errors on Spaces
Browse files
app.py
CHANGED
|
@@ -331,8 +331,22 @@ def _build_youtube_transcript_api() -> YouTubeTranscriptApi:
|
|
| 331 |
return YouTubeTranscriptApi(http_client=_build_youtube_http_client())
|
| 332 |
|
| 333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
def _format_youtube_transcript_error(error: Exception) -> str:
|
| 335 |
-
if
|
| 336 |
proxy_hint = (
|
| 337 |
" Configure `YOUTUBE_HTTP_PROXY` / `YOUTUBE_HTTPS_PROXY` "
|
| 338 |
"or standard `HTTP_PROXY` / `HTTPS_PROXY` in the Space secrets."
|
|
|
|
| 331 |
return YouTubeTranscriptApi(http_client=_build_youtube_http_client())
|
| 332 |
|
| 333 |
|
| 334 |
+
def _looks_like_youtube_ssl_failure(error: Exception) -> bool:
|
| 335 |
+
error_text = str(error)
|
| 336 |
+
ssl_markers = (
|
| 337 |
+
"HTTPSConnectionPool",
|
| 338 |
+
"SSLError",
|
| 339 |
+
"UNEXPECTED_EOF_WHILE_READING",
|
| 340 |
+
"EOF occurred in violation of protocol",
|
| 341 |
+
"Max retries exceeded with url",
|
| 342 |
+
)
|
| 343 |
+
return isinstance(error, (SSLError, RequestException)) or any(
|
| 344 |
+
marker in error_text for marker in ssl_markers
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
|
| 348 |
def _format_youtube_transcript_error(error: Exception) -> str:
|
| 349 |
+
if _looks_like_youtube_ssl_failure(error):
|
| 350 |
proxy_hint = (
|
| 351 |
" Configure `YOUTUBE_HTTP_PROXY` / `YOUTUBE_HTTPS_PROXY` "
|
| 352 |
"or standard `HTTP_PROXY` / `HTTPS_PROXY` in the Space secrets."
|