{"record":{"id":"25758c4b8f2f45bb","repo":"ytdl-org/youtube-dl","slug":"s-site-code-d","errorCode":null,"errorMessage":"%s (site code %d)","messagePattern":"(.+?) \\(site code (.+?)\\)","errorType":"exception","errorClass":"ExtractorError","httpStatus":null,"severity":"error","filePath":"youtube_dl/extractor/neteasemusic.py","lineNumber":143,"sourceCode":"                song_url = try_get(song, lambda x: x['url'])\n                if not song_url:\n                    continue\n                if self._is_valid_url(song_url, info['id'], 'song'):\n                    formats.append({\n                        'url': song_url,\n                        'ext': details.get('extension'),\n                        'abr': float_or_none(song.get('br'), scale=1000),\n                        'format_id': song_format,\n                        'filesize': int_or_none(song.get('size')),\n                        'asr': int_or_none(details.get('sr')),\n                    })\n                elif err == 0:\n                    err = try_get(song, lambda x: x['code'], int)\n\n        if not formats:\n            msg = 'No media links found'\n            if err != 0 and (err < 200 or err >= 400):\n                raise ExtractorError(\n                    '%s (site code %d)' % (msg, err, ), expected=True)\n            else:\n                self.raise_geo_restricted(\n                    msg + ': probably this video is not available from your location due to geo restriction.',\n                    countries=['CN'])\n\n        return formats\n\n    @classmethod\n    def convert_milliseconds(cls, ms):\n        return int(round(ms / 1000.0))\n\n    def query_api(self, endpoint, video_id, note):\n        req = sanitized_Request('%s%s' % (self._API_BASE, endpoint))\n        req.add_header('Referer', self._API_BASE)\n        return self._download_json(req, video_id, note)\n\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/extractor/neteasemusic.py#L125-L161","documentation":"Raised by NetEase Music's format builder when no playable media links were produced AND the returned error code is outside 200-399 — i.e. the site API explicitly errored. The message embeds the numeric site code (e.g. lack of permission or copyright block). For codes inside 200-399 it instead raises a geo-restriction error limited to CN.","triggerScenarios":"Calling NetEaseCloudMusicIE on a song whose API response yields no formats and err (from the per-format 'code' or song['code']) is non-zero and not in [200,400).","commonSituations":"Region-locked NetEase catalog entries; songs removed for licensing; the 200-399 branch (e.g. -110 or in-range codes) usually means 'not available from your location', fixed by CN egress.","solutions":["If the code indicates regional unavailability, retry through a mainland-China proxy: --proxy <cn-proxy>.","Look up the numeric site code in NetEase API references to see if it is copyright/login related; if login-gated, pass cookies with --cookies.","Update youtube-dl / yt-dlp if all songs fail uniformly (API change rather than per-song block)."],"exampleFix":"# before\nyoutube-dl 'http://music.163.com/song?id=123456'\n\n# after\nyoutube-dl --proxy http://cn-proxy:8080 'http://music.163.com/song?id=123456'","handlingStrategy":"retry","validationCode":"import requests\nr = requests.get('http://music.163.com/api/song/detail', params={'id': song_id}).json()\nif not r.get('songs'):\n    print('song unavailable — check region/licensing before extracting')","typeGuard":null,"tryCatchPattern":"from youtube_dl.utils import ExtractorError, GeoRestrictedError\ntry:\n    ydl.extract_info(url)\nexcept GeoRestrictedError:\n    retry_with_proxy(url, region='CN')\nexcept ExtractorError as e:\n    if 'site code' in str(e):\n        code = int(str(e).rsplit(' ', 1)[-1].rstrip(')'))\n        handle_netease_code(code)  # e.g. login-gated vs removed\n    else:\n        raise","preventionTips":["Route NetEase requests via CN egress when catalog access is region-checked.","Map the numeric site code before retrying — only region codes benefit from a proxy.","Pass cookies for licensed tracks tied to an account."],"tags":["geo-restriction","china","music","extractor","expected-error"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}