# Pytube Captions Not Working: Why It Returns None or KeyError, and What to Use in 2026

Source: https://transcript-yt.com/blog/pytube-captions-not-working · Updated 2026-11-27 · TranscriptYT

> Pytube captions returning None or KeyError? Here is why YouTube's player changes broke them, what still works in 2026, and Python code to fetch captions.

Pytube's captions API breaks because the package is no longer maintained: its last release, 15.0.0, shipped about three years ago, while YouTube kept changing the player and the caption format underneath it. The fix that holds up is to stop parsing YouTube yourself and fetch captions from a maintained source, such as the pytubefix fork or the [TranscriptYT API](https://transcript-yt.com/api), which returns timestamped JSON, SRT, or VTT from one HTTP request. This guide shows how to diagnose which failure you have, patch the cases that can still be patched, and swap in code that works.

## Why pytube captions return None or raise KeyError

There are three separate failures that all get reported as "pytube captions not working", and they need different fixes. Look at your traceback first.

The first is a KeyError on the language code, such as KeyError: 'en' or KeyError: 'a.en'. Pytube keys caption tracks by their code, and auto-generated tracks use an a. prefix. A video that only has auto-captions has a.en but no en, so yt.captions['en'] fails. The same lookup through get_by_language_code returns None instead of raising.

The second is an empty yt.captions. Pytube reads the caption track list from the player response. When YouTube changes that response or refuses the request, the list comes back empty and every lookup fails, even though the video shows captions in the browser.

The third is KeyError: 'start' inside generate_srt_captions or xml_caption_to_srt. The track downloads, but pytube's XML parser expects the old caption layout and chokes on the current one. Reports of this error are public in the pytube issue tracker.

The underlying problem is maintenance. Snyk rates pytube as inactive, and PyPI lists 15.0.0 as the final release. Any fix you apply is a patch on top of code nobody is updating.

## Check what pytube actually sees

Before changing anything, print the tracks pytube found. This tells you which of the three failures you have in under a minute.

If the printed list is empty, the player response is the problem and no lookup trick will help. If the list shows a.en but not en, you only need to ask for the right key.

```
from pytube import YouTube

yt = YouTube("https://www.youtube.com/watch?v=5f3Pn-N6yLc")

print(yt.captions)
# [] means the player response had no tracks: pytube is broken for this video
# [<Caption lang="English (auto-generated)" code="a.en">] means ask for a.en

track = yt.captions.get("en") or yt.captions.get("a.en")
if track is None:
    raise SystemExit("No usable caption track found")

xml = track.xml_captions
print(xml[:300])
```

## Fix the KeyError 'start' when converting to SRT

If the track downloads but generate_srt_captions fails, skip pytube's converter and parse the XML yourself. Current caption XML uses p elements with t and d attributes in milliseconds, while the old format used text elements with start and dur in seconds. A parser that handles both avoids the KeyError.

This patch only helps when pytube can still reach the track list. If yt.captions is empty, move on to the next section.

```
import re
import html
import xml.etree.ElementTree as ET

def xml_to_segments(xml_text):
    root = ET.fromstring(xml_text)
    segments = []
    for el in root.iter():
        if el.tag == "p" and el.get("t") is not None:
            start = int(el.get("t")) / 1000
            dur = int(el.get("d", 0)) / 1000
        elif el.tag == "text" and el.get("start") is not None:
            start = float(el.get("start"))
            dur = float(el.get("dur", 0))
        else:
            continue
        text = html.unescape(re.sub(r"<[^>]+>", "", "".join(el.itertext())))
        if text.strip():
            segments.append({"start": start, "duration": dur, "text": text.strip()})
    return segments
```

## Option 1: switch to pytubefix or youtube-transcript-api

The pytubefix package is an actively maintained fork of pytube and keeps the same captions interface, so for many scripts the change is the import line. It is the smallest migration if you also download video or audio streams.

If captions are all you need, the open-source [youtube-transcript-api library](https://transcript-yt.com/blog/youtube-transcript-api-python) is built for that one job and returns segments directly. Both options share a limit: they run on your own IP address, and YouTube blocks most cloud and datacenter ranges. A script that works on your laptop can fail on a server with a request blocked error, which the [RequestBlocked guide](https://transcript-yt.com/blog/youtube-transcript-api-request-blocked) covers in detail.

Sign-in and bot checks hit downloaders too. If you also see them, read the [yt-dlp bot check guide](https://transcript-yt.com/blog/yt-dlp-sign-in-to-confirm-not-a-bot) for what those messages mean.

## Option 2: fetch captions from the TranscriptYT API

A hosted API moves the YouTube side off your machine. You send one HTTPS request with a video URL or 11-character ID and get the transcript back, so there is no player response, XML, or caption URL to maintain. Create a key in your dashboard and follow the [API docs](https://transcript-yt.com/docs) for every parameter.

The default response is JSON with the title, channel, duration, language, timestamped segments, and the full text. The source field says whether the text came from captions or from AI transcription of the audio.

Pass language to pick a track by BCP-47 code, or translate_to to translate it into another language while keeping each segment's timing. Set captionType to manual or auto if you only want uploaded captions or only YouTube's auto-generated ones.

```
import os
import requests

API = "https://transcript-yt.com/v1/transcript"
HEADERS = {"Authorization": f"Bearer {os.environ['TRANSCRIPTYT_KEY']}"}

res = requests.get(
    API,
    params={"url": "https://youtu.be/5f3Pn-N6yLc", "language": "en"},
    headers=HEADERS,
    timeout=120,
)
res.raise_for_status()
data = res.json()

print(data["title"], data["language"], data["source"])
for seg in data["segments"][:5]:
    print(f"{seg['start']:>7.1f}s  {seg['text']}")
```

## Save SRT or VTT files without a converter

Most pytube users want a subtitle file, which is why generate_srt_captions matters to them. With the API you set format to srt, vtt, text, csv, or md and the response body is the file, so there is no conversion step to break. Every format is generated from the same transcript with no extra credit cost. The [caption formats guide](https://transcript-yt.com/blog/youtube-captions-json-srt-vtt) explains when to use each one.

If you only need a file for a few videos and no code, the free [YouTube subtitle downloader](https://transcript-yt.com/youtube-subtitle-downloader) does the same thing in the browser.

```
res = requests.get(
    API,
    params={"url": "5f3Pn-N6yLc", "format": "srt"},
    headers=HEADERS,
    timeout=120,
)
res.raise_for_status()
with open("captions.srt", "w", encoding="utf-8") as f:
    f.write(res.text)

print(res.headers.get("X-Credits-Charged"))
```

## Handle errors and videos with no captions

Errors share one envelope, an error object with a code and a message, so branch on the code. BLOCKED is a temporary upstream block and worth a short retry. NO_CAPTIONS, VIDEO_UNAVAILABLE, and LANGUAGE_NOT_AVAILABLE are final answers for that video. Failed requests are never billed.

A video with no caption track is a dead end for pytube, pytubefix, and youtube-transcript-api, because they only read existing captions. The API can transcribe the audio with AI instead. That costs 1 credit per started minute, needs a paid plan or credit pack, and covers videos up to the length shown in the docs. A Free account gets one free AI transcription of the first 10 minutes of a video, then captions only. See [transcribing a video without captions](https://transcript-yt.com/blog/transcribe-youtube-video-without-captions) for the trade-offs.

Set mode to captions if you never want AI transcription to run.

```
import time

RETRYABLE = {"BLOCKED"}

def get_transcript(video, **params):
    for attempt in range(3):
        res = requests.get(API, params={"url": video, **params}, headers=HEADERS, timeout=120)
        if res.ok:
            return res.json()
        if res.status_code == 402:
            raise RuntimeError("Out of credits")
        error = res.json()["error"]
        if error["code"] not in RETRYABLE:
            raise RuntimeError(f"{error['code']}: {error['message']}")
        time.sleep(2 ** attempt)
    raise RuntimeError("Gave up after 3 attempts")
```

## Which fix should you use

Pick by what you actually need from the video.

- Only the language key is wrong: use get with both en and a.en, as in the diagnostic snippet.
- Track downloads but SRT conversion fails: parse the XML yourself with the patch above.
- yt.captions is empty: pytube cannot read this video's player response, so move to pytubefix or an API.
- Works locally but fails on a server: the IP is blocked, so a hosted API is the lower-maintenance fix.
- You also download video or audio: keep pytubefix for streams and use the API just for captions.
- Many videos or a whole channel: use the [API](https://transcript-yt.com/api) batch and playlist endpoints rather than looping over a scraper.

## Cost of the API route

A transcript request costs 1 credit, and cache hits cost 1 credit too. The Free plan includes 100 credits one time with no card. Paid plans start at Micro, $3 a month for 1,000 credits, then Starter at $9 for 4,000, Growth at $29 for 15,000, and Scale at $79 for 50,000. All paid plans allow 200 requests per minute. For a script that fetches captions for a handful of videos, the free credits are usually enough to confirm the approach before you pay anything.

## FAQ

### Why does pytube yt.captions return an empty list?

Pytube reads the caption track list from YouTube's player response, and pytube 15.0.0 has not been updated in about three years. When YouTube changes or refuses that response, the list comes back empty even though the video has captions in the browser.

### How do I fix KeyError 'a.en' in pytube?

The video only has auto-generated English captions, which pytube keys as a.en instead of en. Look up yt.captions.get('en') or yt.captions.get('a.en'), and print yt.captions first to see which codes exist.

### Is pytube still maintained in 2026?

No. Its last release is 15.0.0 and Snyk rates its maintenance as inactive. The pytubefix fork is actively maintained and keeps a similar interface.

### What is the best pytube alternative for getting YouTube captions in Python?

For captions only, use a caption-focused library or a hosted API instead of a downloader. TranscriptYT returns JSON, SRT, VTT, text, CSV, or Markdown from one request, and the first 100 credits are free.

### Can I get captions for a video that has none?

Not with pytube or other libraries that read caption tracks. TranscriptYT can AI-transcribe the audio on a paid plan or credit pack at 1 credit per started minute.
