unslothai/unsloth · error · HTTPException
Could not reach YouTube.
Error message
Could not reach YouTube.
What it means
502 from POST /youtube/transcript: fetch_transcript failed with an httpx.HTTPError — the outbound HTTP layer could not complete requests to YouTube (DNS failure, connection refused/reset, TLS error, or timeout). The backend logs the specifics ('YouTube transcript fetch failed for <id>') and maps it to a gateway-style 502 because the failure is upstream, not in the request itself.
Source
Thrown at studio/backend/routes/youtube.py:65
text: str
truncated: bool
@router.post("/transcript", response_model = TranscriptResponse)
async def get_transcript(
request: TranscriptRequest, current_subject: str = Depends(get_current_subject)
) -> TranscriptResponse:
video_id = extract_video_id(request.url)
if video_id is None:
raise HTTPException(status_code = 400, detail = "That is not a YouTube video link.")
try:
transcript = await fetch_transcript(video_id, request.languages)
except TranscriptUnavailable as error:
raise HTTPException(status_code = 422, detail = str(error)) from error
except httpx.HTTPError as error:
logger.warning(f"YouTube transcript fetch failed for {video_id}: {error}")
raise HTTPException(
status_code = 502,
detail = "Could not reach YouTube.",
) from error
return TranscriptResponse(
videoId = transcript.video_id,
url = watch_url(transcript.video_id),
title = transcript.title,
author = transcript.author,
lengthSeconds = transcript.length_seconds,
language = transcript.language,
languageCode = transcript.language_code,
isGenerated = transcript.is_generated,
text = transcript.text,
truncated = transcript.truncated,
)
View on GitHub (pinned to 203007d190)
Solutions
- Verify egress: curl https://www.youtube.com from the same host.
- Configure proxy env vars (HTTPS_PROXY) or the proxy's CA in httpx if behind a corporate proxy.
- Retry after a short backoff — many occurrences are transient throttles.
- Check the server log line for the precise httpx error class (ConnectError vs ReadTimeout guides the fix).
Example fix
// client: bounded retry with backoff
for (let i = 0; i < 3; i++) {
try { return await api.post('/youtube/transcript', { url }); }
catch (e) { if (e.status !== 502 || i === 2) throw e; await sleep(2 ** i * 1000); }
} Defensive patterns
Strategy: retry
Validate before calling
// client-side reachability probe before the call (optional)
const online = typeof navigator === 'undefined' ? true : navigator.onLine;
if (!online) throw new Error('You appear to be offline.'); Try / catch
async function withRetry(fn, attempts = 3) {
for (let i = 0; ; i++) {
try { return await fn(); }
catch (e) {
if (e?.status !== 502 || i >= attempts - 1) throw e;
await new Promise(r => setTimeout(r, 2 ** i * 1000));
}
}
} Prevention
- Apply exponential-backoff retry only to 502 (upstream/network), not 4xx
- Configure HTTPS_PROXY/CA for corporate networks on the backend host
- Check the backend log for the underlying httpx error class before assuming code fault
When it happens
Trigger: Studio host has no internet or a blocking firewall/proxy; YouTube returns RSTs / rate-limits the IP; corporate MITM proxy with an untrusted CA breaks TLS; transient network blip during fetch.
Common situations: Air-gapped or proxied dev environments; heavy polling from one IP triggering throttling; DNS misconfiguration in a container.
Related errors
- Could not reach ChatGPT authentication.
- ChatGPT returned an invalid authorization response.
- ChatGPT Codex endpoint returned a forbidden redirect.
- YouTube will not play this video.
- YouTube returned an unreadable response.
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/075a07811e577bf7.
Report an issue: GitHub.