{"record":{"id":"4fd8024d1ca76723","repo":"ytdl-org/youtube-dl","slug":"s-returns-error-d","errorCode":null,"errorMessage":"%s returns error %d","messagePattern":"(.+?) returns error (.+?)","errorType":"exception","errorClass":"ExtractorError","httpStatus":null,"severity":"error","filePath":"youtube_dl/extractor/bilibili.py","lineNumber":119,"sourceCode":"            },\n            'params': {\n                'skip_download': True,  # Test metadata only\n            },\n        }]\n    }, {\n        # new BV video id format\n        'url': 'https://www.bilibili.com/video/BV1JE411F741',\n        'only_matching': True,\n    }]\n\n    _APP_KEY = 'iVGUTjsxvpLeuDCf'\n    _BILIBILI_KEY = 'aHRmhWMLkdeMuILqORnYZocwMBpMEOdt'\n\n    def _report_error(self, result):\n        if 'message' in result:\n            raise ExtractorError('%s said: %s' % (self.IE_NAME, result['message']), expected=True)\n        elif 'code' in result:\n            raise ExtractorError('%s returns error %d' % (self.IE_NAME, result['code']), expected=True)\n        else:\n            raise ExtractorError('Can\\'t extract Bangumi episode ID')\n\n    def _real_extract(self, url):\n        url, smuggled_data = unsmuggle_url(url, {})\n\n        mobj = re.match(self._VALID_URL, url)\n        video_id = mobj.group('id') or mobj.group('id_bv')\n        anime_id = mobj.group('anime_id')\n        webpage = self._download_webpage(url, video_id)\n\n        if 'anime/' not in url:\n            cid = self._search_regex(\n                r'\\bcid(?:[\"\\']:|=)(\\d+)', webpage, 'cid',\n                default=None\n            ) or compat_parse_qs(self._search_regex(\n                [r'EmbedPlayer\\([^)]+,\\s*\"([^\"]+)\"\\)',\n                 r'EmbedPlayer\\([^)]+,\\s*\\\\\"([^\"]+)\\\\\"\\)',","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/extractor/bilibili.py#L101-L137","documentation":"The second branch of BiliBiliBangumiIE._report_error: the API result dict has no 'message' key but does have a 'code' key, so the error reports the numeric code ('%s returns error %d'). Expected=True. This branch typically fires when the API signals failure with only a status code and no human-readable text.","triggerScenarios":"A Bangumi API response shaped like {'code': -404, ...} or {'code': <negative/nonzero>} without a message — unknown season/episode ids, expired signed URLs, or API versions that omit the message field. The %d format also implies code must be an integer; a string code would raise a format error instead.","commonSituations":"Wrong anime_id/episode_id parsed from the URL; API contract change dropping the message field; signed-request staleness; bangumi entries delisted with bare error codes.","solutions":["Map the code: common Bilibili codes are -400 (bad request), -404 (not found), -799 (rate limit); fix the request accordingly.","Verify the bangumi id by opening the page in a browser and comparing with the extractor's captured anime/episode id.","If code arrives as a string in newer API versions, coerce before formatting (%d on a str raises) and report the schema change upstream.","For rate limiting (-799 style), back off and retry rather than hammering."],"exampleFix":"// before\nelif 'code' in result:\n    raise ExtractorError('%s returns error %d' % (self.IE_NAME, result['code']), expected=True)\n\n// after: tolerate string codes and show them safely\nelif 'code' in result:\n    code = result['code']\n    raise ExtractorError('%s returns error %s' % (self.IE_NAME, code), expected=True)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ydl.extract_info(bangumi_url)\nexcept ExtractorError as e:\n    m = re.search(r'returns error (-?\\d+)', str(e))\n    if m:\n        code = int(m.group(1))\n        if code in (-799,):  # rate limit style\n            backoff_and_retry(bangumi_url)\n        elif code == -404:\n            mark_not_found(bangumi_url)\n    else:\n        raise","preventionTips":["Map Bilibili numeric codes (-400 bad request, -404 not found, rate-limit codes) to concrete handling.","Throttle request rates to Bilibili to avoid code-based rate-limit responses.","Watch for string codes (would crash %d) — a sign the API schema changed."],"tags":["bilibili","bangumi","api-error","error-code","extractor"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}