crewAIInc/crewAI · error · ValueError

Unable to load YouTube channel {channel_url}: {e!s}

Error message

Unable to load YouTube channel {channel_url}: {e!s}

What it means

The channel loader's outer catch-all: any exception during channel metadata fetching, video URL enumeration, or per-video processing is wrapped as ValueError('Unable to load YouTube channel ...') with the cause chained. Note that per-video failures are NOT fatal — they are appended into the content as 'Error loading video: ...' strings — so this outer error usually means the channel itself could not be fetched.

Source

Thrown at lib/crewai-tools/src/crewai_tools/rag/loaders/youtube_channel_loader.py:139

                                if text_parts:
                                    preview = " ".join(text_parts)[:500]
                                    content_parts.append(
                                        f"   Transcript Preview: {preview}..."
                                    )
                        except Exception:
                            content_parts.append("   Transcript: Not available")

                    except Exception as e:
                        content_parts.append(f"\n{i}. Error loading video: {e!s}")

            except ImportError:
                for i, video_url in enumerate(video_urls, 1):
                    content_parts.append(f"\n{i}. {video_url}")

            content = "\n".join(content_parts)

        except Exception as e:
            raise ValueError(
                f"Unable to load YouTube channel {channel_url}: {e!s}"
            ) from e

        return LoaderResult(
            content=content,
            source=channel_url,
            metadata=metadata,
            doc_id=self.generate_doc_id(source_ref=channel_url, content=content),
        )

    @staticmethod
    def _extract_video_id(url: str) -> str | None:
        """Extract video ID from YouTube URL."""
        patterns = [
            r"(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/|youtube\.com\/v\/)([^&\n?#]+)",
        ]

        for pattern in patterns:

View on GitHub (pinned to 754d7323be)

Solutions

  1. Inspect e.__cause__ — for pytube scrape failures it is usually RegexMatchError, which means the installed pytube is outdated.
  2. Upgrade pytube to the latest release: uv add 'pytube @ latest' — scrape fixes land regularly.
  3. If pytube is unmaintained for your URL shape, consider pytubefix as a drop-in replacement (same import path).
  4. Verify the channel URL opens in a browser from the same network; restricted or removed channels cannot be loaded.
  5. Note that individual broken videos do not raise this — degraded content with 'Error loading video' entries means partial success, not total failure.

Example fix

# shell, before: pip install pytube (old version, RegexMatchError)
# after:
# uv pip install -U pytubefix   # maintained fork, same API surface
result = loader.load(SourceContent(path="https://www.youtube.com/@handle"))
Defensive patterns

Strategy: retry

Validate before calling

def pytube_can_fetch_channel(channel_url: str) -> bool:
    try:
        from pytube import Channel
        ch = Channel(channel_url)
        _ = ch.channel_name
        return True
    except Exception:
        return False

Try / catch

try:
    result = channel_loader.load(src)
except ValueError as e:
    if is_transient_network_error(e.__cause__):
        backoff_and_retry(src)
    elif "RegexMatchError" in repr(e.__cause__):
        upgrade_pytube()  # YouTube layout changed

Prevention

When it happens

Trigger: pytube's Channel(channel_url) failing to scrape the channel page: YouTube layout changes breaking pytube, age/region-restricted channels, network errors, or an empty channel raising during channel_name/channel_id access. A pytube internals change ('regex match error') is the classic cause.

Common situations: pytube frequently breaks when YouTube changes its page structure — an environment that worked yesterday can fail today without any code change; channels with zero videos; running from datacenter IPs that YouTube challenges.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/294f0f75a992506c. Report an issue: GitHub.