crewAIInc/crewAI · error · ValueError

Unable to access repository {repo_name}: {e}

Error message

Unable to access repository {repo_name}: {e}

What it means

Raised by GithubLoader.load() when g.get_repo(repo_name) throws GithubException — the PyGithub call to the GitHub API failed. Common causes: repository does not exist (404), the repo is private and no/insufficient token was supplied (401/403), or the token lacks scopes. The original exception is chained so the HTTP status is visible in the message.

Source

Thrown at lib/crewai-tools/src/crewai_tools/rag/loaders/github_loader.py:43

        gh_token = metadata.get("gh_token")
        content_types = metadata.get("content_types", ["code", "repo"])

        repo_url = source.source
        if not repo_url.startswith("https://github.com/"):
            raise ValueError(f"Invalid GitHub URL: {repo_url}")

        parts = repo_url.replace("https://github.com/", "").strip("/").split("/")
        if len(parts) < 2:
            raise ValueError(f"Invalid GitHub repository URL: {repo_url}")

        repo_name = f"{parts[0]}/{parts[1]}"

        g = Github(gh_token) if gh_token else Github()

        try:
            repo = g.get_repo(repo_name)
        except GithubException as e:
            raise ValueError(f"Unable to access repository {repo_name}: {e}") from e

        all_content = []

        if "repo" in content_types:
            all_content.append(f"Repository: {repo.full_name}")
            all_content.append(f"Description: {repo.description or 'No description'}")
            all_content.append(f"Language: {repo.language or 'Not specified'}")
            all_content.append(f"Stars: {repo.stargazers_count}")
            all_content.append(f"Forks: {repo.forks_count}")
            all_content.append("")

        if "code" in content_types:
            try:
                readme = repo.get_readme()
                all_content.append("README:")
                all_content.append(readme.decoded_content.decode(errors="ignore"))
                all_content.append("")
            except GithubException:

View on GitHub (pinned to 754d7323be)

Solutions

  1. Pass a token: GithubLoader().load(src, metadata={'gh_token': os.environ['GITHUB_TOKEN']}) — this raises the rate limit to 5000/hour and unlocks private repos you can access.
  2. Verify the repo exists and the spelling/case is right by opening https://github.com/owner/repo or calling the API with curl.
  3. For fine-grained PATs, grant the repository read access; for classic tokens ensure 'repo' scope for private repos.
  4. Handle rate limiting with backoff or by caching results between runs.

Example fix

# before
result = GithubLoader().load(SourceContent('https://github.com/acme/private-repo'))  # 404

# after
import os
result = GithubLoader().load(
    SourceContent('https://github.com/acme/private-repo'),
    metadata={'gh_token': os.environ['GITHUB_TOKEN']},
)
Defensive patterns

Strategy: try-catch

Validate before calling

import os\n\ndef github_token() -> str | None:\n    tok = os.environ.get('GITHUB_TOKEN')\n    if not tok:\n        raise RuntimeError('GITHUB_TOKEN not set; private repos and high rate limits need it')\n    return tok

Try / catch

try:\n    result = GithubLoader().load(source, metadata={'gh_token': tok})\nexcept ValueError as e:\n    if 'Unable to access repository' in str(e):\n        if is_rate_limited():\n            sleep_and_retry_later()\n        else:\n            raise RuntimeError('check repo name and token scopes') from e\n    raise

Prevention

When it happens

Trigger: Loading a private repo without passing metadata={'gh_token': ...}; using a revoked or expired personal access token; naming a repo that was renamed or deleted; hitting GitHub rate limits (403) because requests are made anonymously and the unauthenticated quota (60/hour/IP) is exhausted.

Common situations: Forgetting that unauthenticated GitHub API access is rate-limited to 60 requests/hour; fine-grained PATs missing the repo's read permission; org repos with SSO the token has not been authorized for; CI environments where GITHUB_TOKEN was not forwarded into metadata.

Related errors


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