xtekky/gpt4free · error · Exception

Operation failed after {retries} attempts.

Error message

Operation failed after {retries} attempts.

What it means

Raised by MarkItDown's YouTube converter _retry_operation() after every attempt of the wrapped operation raised an exception within the retry budget (default 3 attempts, 2s delay). The printed 'Attempt N failed' lines carry the real cause; this final Exception only signals exhaustion, and it discards the last exception object (message only via prints).

Source

Thrown at g4f/integration/markitdown/_youtube_converter.py:313

                if k == key:
                    return json[k]
                if result := self._findKey(v, key):
                    return result
        return None

    def _retry_operation(self, operation, retries=3, delay=2):
        """Retries the operation if it fails."""
        attempt = 0
        while attempt < retries:
            try:
                return operation()  # Attempt the operation
            except Exception as e:
                print(f"Attempt {attempt + 1} failed: {e}")
                if attempt < retries - 1:
                    time.sleep(delay)  # Wait before retrying
                attempt += 1
        # If all attempts fail, raise the last exception
        raise Exception(f"Operation failed after {retries} attempts.")

View on GitHub (pinned to 973504e177)

Solutions

  1. Check the preceding 'Attempt N failed: ...' console output — it holds the root-cause message; fix that (e.g. 403 => proxy/VPN, HTTPError => missing captions).
  2. Test the same URL with yt-dlp --write-auto-sub locally to see if captions are obtainable at all.
  3. Update the yt-dlp/pytube dependency to the latest version, since YouTube extraction breaks frequently.
  4. For batch jobs, add backoff or slow down; wrap the convert call in try/except and skip un-captioned videos.

Example fix

// before
result = md.convert("https://www.youtube.com/watch?v=XXXX")  # raises generic Exception after 3 attempts

// after
try:
    result = md.convert("https://www.youtube.com/watch?v=XXXX")
except Exception as e:
    logger.warning("youtube transcript unavailable for %s: %s", url, e)
    result = None  # graceful skip in batch processing
Defensive patterns

Strategy: retry

Try / catch

try:
    result = md.convert(youtube_url)
except Exception as e:
    if "Operation failed after" in str(e):
        logger.warning("youtube extraction failed for %s; check captions/network", youtube_url)
        result = None
    else:
        raise

Prevention

When it happens

Trigger: Transcript/caption fetching for a YouTube URL failing 3 times in a row — typical causes: network/proxy blocks YouTube, the video has no captions, YouTube changed its page/schema and pytube/yt-dlp data extraction breaks, or an HTTP 429/403 rate limit persists across retries.

Common situations: Server IPs (cloud providers) blocked by YouTube; videos with captions disabled; version drift between the vendored converter and YouTube's HTML; rate limiting under batch conversion jobs.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/03bc20d6201ca27c. Report an issue: GitHub.