{"record":{"id":"5c764f3b37c0e5de","repo":"NanmiCoder/MediaCrawler","slug":"bilibililogin-begin-invalid-login-type-currently","errorCode":null,"errorMessage":"[BilibiliLogin.begin] Invalid Login Type Currently only supported qrcode or phone or cookie ...","messagePattern":"\\[BilibiliLogin\\.begin\\] Invalid Login Type Currently only supported qrcode or phone or cookie \\.\\.\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"media_platform/bilibili/login.py","lineNumber":64,"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 bilibili\"\"\"\n        utils.logger.info(\"[BilibiliLogin.begin] Begin login Bilibili ...\")\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(\n                \"[BilibiliLogin.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        if cookie_dict.get(\"SESSDATA\", \"\") or cookie_dict.get(\"DedeUserID\"):\n            return True\n        return False\n\n    async def login_by_qrcode(self):\n        \"\"\"login bilibili website and keep webdriver login state\"\"\"\n        utils.logger.info(\"[BilibiliLogin.login_by_qrcode] Begin login bilibili by qrcode ...\")","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/bilibili/login.py#L46-L82","documentation":"ValueError from BilibiliLogin.begin when the global config.LOGIN_TYPE is not one of the three supported literals 'qrcode', 'phone', 'cookie'. Login dispatch is a simple if/elif over the config string, and any other value aborts login before any browser interaction.","triggerScenarios":"LOGIN_TYPE set to 'qr', 'sms', 'Cookie' (capitalized), 'password', or left empty in config/base_config.py or env override; config value read from a .env that quotes or spaces the value.","commonSituations":"Editing the sample config and guessing at allowed values; CI passing a different LOGIN_TYPE than local runs; version drift where supported login methods changed.","solutions":["Set LOGIN_TYPE to exactly 'qrcode', 'phone', or 'cookie' (lowercase) in config.","For headless/automated runs prefer 'cookie' with a valid cookie string, since qrcode needs a human scan.","Validate the value at startup against the allowed set and fail fast with a clear message."],"exampleFix":"# before\nconfig.LOGIN_TYPE = 'qr'\n\n# after\nconfig.LOGIN_TYPE = 'qrcode'","handlingStrategy":"validation","validationCode":"from config import config\nassert config.LOGIN_TYPE in {'qrcode', 'phone', 'cookie'}, f'bad LOGIN_TYPE: {config.LOGIN_TYPE!r}'","typeGuard":"def is_valid_login_type(t: str) -> bool:\n    return t in {'qrcode', 'phone', 'cookie'}","tryCatchPattern":"try:\n    await BilibiliLogin(...).begin()\nexcept ValueError as e:\n    if 'Invalid Login Type' in str(e):\n        raise SystemExit('set LOGIN_TYPE to qrcode, phone, or cookie in config') from e","preventionTips":["Use exact lowercase literals in config","Prefer cookie login for headless/CI runs","Validate LOGIN_TYPE at process start, before Playwright launches"],"tags":["bilibili","login","configuration","valueerror"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}