{"record":{"id":"53dbb29cc064a3e5","repo":"ytdl-org/youtube-dl","slug":"error-parsed-json-message-from-401-response","errorCode":null,"errorMessage":"error (parsed JSON 'Message' from 401 response)","messagePattern":"error \\(parsed JSON 'Message' from 401 response\\)","errorType":"exception","errorClass":"ExtractorError","httpStatus":401,"severity":"error","filePath":"youtube_dl/extractor/toutv.py","lineNumber":63,"sourceCode":"        if email is None:\n            return\n        try:\n            self._access_token = self._download_json(\n                'https://services.radio-canada.ca/toutv/profiling/accounts/login',\n                None, 'Logging in', data=json.dumps({\n                    'ClientId': self._CLIENT_KEY,\n                    'ClientSecret': '34026772-244b-49b6-8b06-317b30ac9a20',\n                    'Email': email,\n                    'Password': password,\n                    'Scope': 'id.write media-validation.read',\n                }).encode(), headers={\n                    'Authorization': 'client-key ' + self._CLIENT_KEY,\n                    'Content-Type': 'application/json;charset=utf-8',\n                })['access_token']\n        except ExtractorError as e:\n            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:\n                error = self._parse_json(e.cause.read().decode(), None)['Message']\n                raise ExtractorError(error, expected=True)\n            raise\n        self._claims = self._call_api('validation/v2/getClaims')['claims']\n\n    def _real_extract(self, url):\n        path = self._match_id(url)\n        metadata = self._download_json(\n            'https://services.radio-canada.ca/toutv/presentation/%s' % path, path, query={\n                'client_key': self._CLIENT_KEY,\n                'device': 'web',\n                'version': 4,\n            })\n        # IsDrm does not necessarily mean the video is DRM protected (see\n        # https://github.com/ytdl-org/youtube-dl/issues/13994).\n        if metadata.get('IsDrm'):\n            self.report_warning('This video is probably DRM protected.', path)\n        video_id = metadata['IdMedia']\n        details = metadata['Details']\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/ytdl-org/youtube-dl/blob/956b8c585591b401a543e409accb163eeaaa1193/youtube_dl/extractor/toutv.py#L45-L81","documentation":"Raised by TouTvIE (Radio-Canada) during login when the OAuth token request returns HTTP 401; the extractor parses the JSON body and re-raises its 'Message' field (e.g. invalid credentials). Expected=True, so it is reported as an authentication failure with the server's own text.","triggerScenarios":"Passing --username/--password for a touvieres canadien account where the token endpoint at services.radio-canada.ca returns 401: wrong password, changed client key/secret, or the R&C auth API rejecting the legacy login flow.","commonSituations":"Typos in credentials; expired/changed accounts; Radio-Canada migrating auth so the hardcoded ClientSecret no longer validates; older youtube-dl versions predating fixes to the TouTV login flow.","solutions":["Verify the username/password on the tou.tv website in a browser","Prefer cookie-based auth: export cookies after browser login and use --cookies (yt-dlp), avoiding the legacy password flow entirely","Update to yt-dlp, which dropped/reworked TouTV password login","If you maintain a fork, refresh _CLIENT_KEY/ClientSecret from the current website requests"],"exampleFix":"# before: password login hits 401 and surfaces the raw Message\nyt-dlp --username USER --password PASS URL\n# after: reuse an authenticated browser session\nyt-dlp --cookies-from-browser firefox URL","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ydl.download([url])\nexcept ExtractorError as e:\n    if e.expected and e.cause_is_401():\n        # fall back to cookie-based session instead of password login\n        run(['yt-dlp', '--cookies-from-browser', 'firefox', url])","preventionTips":["Prefer cookie auth over legacy password login for Radio-Canada properties","Verify credentials on the website first","Use a maintained fork (yt-dlp) since youtube-dl's TouTV login is stale"],"tags":["extractor","auth","oauth","http-401","expected"],"backgroundTag":null,"analyzedSha":"956b8c585591b401a543e409accb163eeaaa1193","analyzedAt":"2026-08-14T18:59:47.863Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}