{"record":{"id":"eba7bda2d92628d6","repo":"NanmiCoder/MediaCrawler","slug":"kuaishoulogin-begin-invalid-login-type-currently","errorCode":null,"errorMessage":"[KuaishouLogin.begin] Invalid Login Type Currently only supported qrcode or phone or cookie ...","messagePattern":"\\[KuaishouLogin\\.begin\\] Invalid Login Type Currently only supported qrcode or phone or cookie \\.\\.\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"media_platform/kuaishou/login.py","lineNumber":59,"sourceCode":"                 cookie_str: str = \"\"\n                 ):\n        config.LOGIN_TYPE = login_type\n        self.browser_context = browser_context\n        self.context_page = context_page\n        self.login_phone = login_phone\n        self.cookie_str = cookie_str\n\n    async def begin(self):\n        \"\"\"Start login xiaohongshu\"\"\"\n        utils.logger.info(\"[KuaishouLogin.begin] Begin login kuaishou ...\")\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(\"[KuaishouLogin.begin] Invalid Login Type Currently only supported qrcode or phone or cookie ...\")\n\n    @retry(stop=stop_after_attempt(600), wait=wait_fixed(1), retry=retry_if_result(lambda value: value is False))\n    async def check_login_state(self) -> bool:\n        \"\"\"\n            Check if the current login status is successful and return True otherwise return False\n            retry decorator will retry 20 times if the return value is False, and the retry interval is 1 second\n            if max retry times reached, raise RetryError\n        \"\"\"\n        current_cookie = await self.browser_context.cookies()\n        _, cookie_dict = utils.convert_cookies(current_cookie)\n        kuaishou_pass_token = cookie_dict.get(\"passToken\")\n        if kuaishou_pass_token:\n            return True\n        return False\n\n    async def login_by_qrcode(self):\n        \"\"\"login kuaishou website and keep webdriver login state\"\"\"\n        utils.logger.info(\"[KuaishouLogin.login_by_qrcode] Begin login kuaishou by qrcode ...\")","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/kuaishou/login.py#L41-L77","documentation":"Raised by KuaishouLogin.begin when the global config.LOGIN_TYPE is not one of the three accepted values ('qrcode', 'phone', 'cookie'). The dispatcher at media_platform/kuaishou/login.py:59 is a pure string comparison chain with no normalization, so any other value (typo, case mismatch, unset) falls into the else branch. It is a configuration validation error thrown before any browser interaction starts.","triggerScenarios":"Calling await kuaishou_login.begin() (normally from the Kuaishou crawler's login flow) while config.LOGIN_TYPE is anything except exactly 'qrcode', 'phone', or 'cookie' — e.g. 'QRCode', 'qrcode ', 'sms', or an empty/unset value in the environment/config source that populates config.LOGIN_TYPE.","commonSituations":"Typos or wrong casing in the LOGIN_TYPE env var or base_config; newer config values (e.g. 'all') supported by other platforms but not Kuaishou; copying a config file from another platform module; LOGIN_TYPE left empty because the config loader defaults were changed.","solutions":["Set config.LOGIN_TYPE to exactly 'qrcode', 'phone', or 'cookie' (lowercase, no whitespace) in the config source feeding config.LOGIN_TYPE","Check the actual value at runtime (print/log config.LOGIN_TYPE) to spot casing or trailing-space issues","If you need another type, implement a login_by_* method and extend the elif chain in KuaishouLogin.begin"],"exampleFix":"# before\nLOGIN_TYPE=QRCode  # or 'sms'\n\n# after\nLOGIN_TYPE=qrcode","handlingStrategy":"validation","validationCode":"import config\nassert config.LOGIN_TYPE in {\"qrcode\", \"phone\", \"cookie\"}, (\n    f\"LOGIN_TYPE must be qrcode|phone|cookie, got {config.LOGIN_TYPE!r}\"\n)","typeGuard":"def is_valid_kuaishou_login_type(value: str) -> bool:\n    return isinstance(value, str) and value.strip().lower() in {\"qrcode\", \"phone\", \"cookie\"}","tryCatchPattern":null,"preventionTips":["Validate LOGIN_TYPE once at process startup before any crawler begins","Normalize the value (strip().lower()) where config is loaded","Keep per-platform supported login types documented next to the config default"],"tags":["configuration","login","kuaishou","validation"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}