yt-dlp/yt-dlp · error · ExtractorError

Invalid facebook redirect URL

Error message

Invalid facebook redirect URL

What it means

FacebookRedirectIE handles facebook.com/l.php (and similar) outbound redirect links, taking the target from the 'u' query parameter. If that parameter is missing or empty (url_or_none returns None), the URL cannot be resolved and this expected error is raised. The link is malformed — nothing to redirect to.

Source

Thrown at yt_dlp/extractor/facebook.py:954

            'tags': 'count:11',
            'duration': 3332,
            'live_status': 'not_live',
            'thumbnail': r're:https?://i\.ytimg\.com/vi/.+',
            'channel_url': 'https://www.youtube.com/channel/UCGBpxWJr9FNOcFYA5GkKrMg',
            'availability': 'public',
            'uploader_url': 'http://www.youtube.com/user/brtvofficial',
            'upload_date': '20150917',
            'age_limit': 0,
            'view_count': int,
            'like_count': int,
        },
        'skip': 'Youtube video is now private',
    }]

    def _real_extract(self, url):
        redirect_url = url_or_none(parse_qs(url).get('u', [None])[-1])
        if not redirect_url:
            raise ExtractorError('Invalid facebook redirect URL', expected=True)
        return self.url_result(redirect_url)


class FacebookReelIE(InfoExtractor):
    _VALID_URL = r'https?://(?:[\w-]+\.)?facebook\.com/reel/(?P<id>\d+)'
    IE_NAME = 'facebook:reel'
    _TESTS = [{
        'url': 'https://www.facebook.com/reel/1195289147628387',
        'md5': 'aeb0153ecb2eaacdf2dc2bf88f593fef',
        'info_dict': {
            'id': '1195289147628387',
            'ext': 'mp4',
            'title': '9.7K views · 352 reactions | When your trying to help your partner out with an arrest and #FAAFO games begin. Let the “Slapathon” commence!! 👊👋 | Beast Camp Training',
            'description': 'md5:5a767dc7e78718667b150a7facc4a34f',
            'uploader': '9.7K views &#xb7; 352 reactions | When your trying to help your partner out with an arrest and #FAAFO games begin. Let the &#x201c;Slapathon&#x201d; commence!! &#x1f44a;&#x1f44b; | Beast Camp Training',
            'uploader_id': '100040874179269',
            'duration': 9.579,
            'thumbnail': r're:https?://scontent\.fitm\d-1\.fna\.fbcdn\.net/.+',

View on GitHub (pinned to 81ecd58b13)

Solutions

  1. Get the full original link including its query string and retry.
  2. Better: open the l.php link once in a browser and copy the final destination URL; pass that directly to yt-dlp.
  3. In scripts, validate that the redirect URL has a non-empty 'u' query param before handing it to yt-dlp.

Example fix

# before
yt-dlp 'https://www.facebook.com/l.php'
# ERROR: [facebook:redirect] Invalid facebook redirect URL

# after
yt-dlp 'https://www.facebook.com/l.php?u=https%3A%2F%2Fexample.com%2Fvideo'
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse, parse_qs

def resolve_fb_redirect(url: str):
    q = parse_qs(urlparse(url).query)
    target = q.get('u', [None])[-1]
    if not target:
        raise ValueError(f'{url} is a facebook redirect link without a u= target')
    return target  # hand THIS to yt-dlp

Try / catch

from yt_dlp.utils import ExtractorError

try:
    info = ydl.extract_info(url, download=True)
except ExtractorError as e:
    if e.expected and 'Invalid facebook redirect URL' in str(e):
        notify_user('The facebook.com/l.php link lost its u= parameter; re-copy the full link')
        raise

Prevention

When it happens

Trigger: Matching a facebook.com/l.php URL whose query string lacks u= (or has it empty), e.g. truncated copy-paste, sanitized referrer-stripped links, or hand-built l.php URLs.

Common situations: URLs mangled by chat clients that strip query parameters; scraping pipelines that drop query strings; users hand-editing FB links.

Related errors


AI-assisted analysis of yt-dlp/yt-dlp@81ecd58b13 (2026-08-22). Data as JSON: /api/errors/71ea1b9be6ba833d. Report an issue: GitHub.