{"record":{"id":"d4d27fee109cf36c","repo":"NanmiCoder/MediaCrawler","slug":"xiaohongshulogin-begin-i-nvalid-login-type-curren","errorCode":null,"errorMessage":"[XiaoHongShuLogin.begin]I nvalid Login Type Currently only supported qrcode or phone or cookies ...","messagePattern":"\\[XiaoHongShuLogin\\.begin\\]I nvalid Login Type Currently only supported qrcode or phone or cookies \\.\\.\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"media_platform/xhs/login.py","lineNumber":97,"sourceCode":"        \n        # If web_session has changed, consider the login successful\n        if current_web_session and current_web_session != no_logged_in_session:\n            utils.logger.info(\"[XiaoHongShuLogin.check_login_state] Login status confirmed by Cookie (web_session changed).\")\n            return True\n\n        return False\n\n    async def begin(self):\n        \"\"\"Start login xiaohongshu\"\"\"\n        utils.logger.info(\"[XiaoHongShuLogin.begin] Begin login xiaohongshu ...\")\n        if config.LOGIN_TYPE == \"qrcode\":\n            await self.login_by_qrcode()\n        elif config.LOGIN_TYPE == \"phone\":\n            await self.login_by_mobile()\n        elif config.LOGIN_TYPE == \"cookie\":\n            await self.login_by_cookies()\n        else:\n            raise ValueError(\"[XiaoHongShuLogin.begin]I nvalid Login Type Currently only supported qrcode or phone or cookies ...\")\n\n    async def login_by_mobile(self):\n        \"\"\"Login xiaohongshu by mobile\"\"\"\n        utils.logger.info(\"[XiaoHongShuLogin.login_by_mobile] Begin login xiaohongshu by mobile ...\")\n        await asyncio.sleep(1)\n        try:\n            # After entering Xiaohongshu homepage, the login dialog may not pop up automatically, need to manually click login button\n            login_button_ele = await self.context_page.wait_for_selector(\n                selector=\"xpath=//*[@id='app']/div[1]/div[2]/div[1]/ul/div[1]/button\",\n                timeout=5000\n            )\n            await login_button_ele.click()\n            # The login dialog has two forms: one shows phone number and verification code directly\n            # The other requires clicking to switch to phone login\n            element = await self.context_page.wait_for_selector(\n                selector='xpath=//div[@class=\"login-container\"]//div[@class=\"other-method\"]/div[1]',\n                timeout=5000\n            )","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/xhs/login.py#L79-L115","documentation":"ValueError raised by XiaoHongShuLogin.begin when config.LOGIN_TYPE is not 'qrcode', 'phone', or 'cookies' (note: xhs uses 'cookies' with an s, unlike weibo/zhihu). Thrown before login starts; purely a config-validation failure.","triggerScenarios":"LOGIN_TYPE misspelled or set to an unsupported value (e.g. 'cookie' for xhs where the accepted literal is 'cookies', 'scan', 'sms'), or config copied from the weibo section.","commonSituations":"Cross-platform config reuse where the user assumes 'cookie' works everywhere; typo in --lt CLI argument; trailing whitespace or wrong case.","solutions":["Set LOGIN_TYPE to exactly 'qrcode', 'phone', or 'cookies' in the xhs config.","Double-check the plural 'cookies' spelling - the most common trap coming from weibo/zhihu configs.","Check the value passed with --lt on the command line."],"exampleFix":"# before\nLOGIN_TYPE = \"cookie\"   # works for weibo, fails for xhs\n# after\nLOGIN_TYPE = \"cookies\"","handlingStrategy":"validation","validationCode":"import config\nassert config.LOGIN_TYPE in {\"qrcode\", \"phone\", \"cookies\"}, f\"bad LOGIN_TYPE: {config.LOGIN_TYPE!r}\"","typeGuard":"def is_valid_xhs_login_type(value: str) -> bool:\n    return isinstance(value, str) and value in {\"qrcode\", \"phone\", \"cookies\"}","tryCatchPattern":null,"preventionTips":["Remember xhs accepts 'cookies' (plural), unlike weibo's 'cookie'.","Validate LOGIN_TYPE once at startup against a per-platform allowlist.","Avoid hand-editing config late at night - this error is almost always a typo."],"tags":["xhs","login","config","validation"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}