{"record":{"id":"146e282dd73987aa","repo":"NanmiCoder/MediaCrawler","slug":"douyinlogin-begin-invalid-login-type-currently-o","errorCode":null,"errorMessage":"[DouYinLogin.begin] Invalid Login Type Currently only supported qrcode or phone or cookie ...","messagePattern":"\\[DouYinLogin\\.begin\\] Invalid Login Type Currently only supported qrcode or phone or cookie \\.\\.\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"media_platform/douyin/login.py","lineNumber":70,"sourceCode":"\n    async def begin(self):\n        \"\"\"\n            Start login douyin website\n            The verification accuracy of the slider verification is not very good... If there are no special requirements, it is recommended not to use Douyin login, or use cookie login\n        \"\"\"\n\n        # popup login dialog\n        await self.popup_login_dialog()\n\n        # select login type\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(\"[DouYinLogin.begin] Invalid Login Type Currently only supported qrcode or phone or cookie ...\")\n\n        # If the page redirects to the slider verification page, need to slide again\n        await asyncio.sleep(6)\n        current_page_title = await self.context_page.title()\n        if \"验证码中间页\" in current_page_title:\n            await self.check_page_display_slider(move_step=3, slider_level=\"hard\")\n\n        # check login state\n        utils.logger.info(f\"[DouYinLogin.begin] login finished then check login state ...\")\n        try:\n            await self.check_login_state()\n        except RetryError:\n            utils.logger.info(\"[DouYinLogin.begin] login failed please confirm ...\")\n            sys.exit()\n\n        # wait for redirect\n        wait_redirect_seconds = 5\n        utils.logger.info(f\"[DouYinLogin.begin] Login successful then wait for {wait_redirect_seconds} seconds redirect ...\")","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/douyin/login.py#L52-L88","documentation":"ValueError from DouYinLogin.begin when config.LOGIN_TYPE is not exactly 'qrcode', 'phone', or 'cookie'. After popping up the login dialog the method dispatches on the global config string; an unknown value raises before login proceeds. (Notably this happens after popup_login_dialog, so a browser page is already open when it fires.)","triggerScenarios":"LOGIN_TYPE set to 'qrcode ' (trailing space), 'SMS', 'account', or empty in config/base_config.py or an environment override; CI injecting a different LOGIN_TYPE than expected.","commonSituations":"Hand-editing the sample config and guessing values; values read from .env files retaining quotes; case-sensitive literals copied from tutorials.","solutions":["Set LOGIN_TYPE to exactly one of 'qrcode', 'phone', 'cookie' (lowercase, no surrounding whitespace).","For headless automation use 'cookie' login with a fresh cookie string; qrcode requires manual scanning.","Assert the allowed value early at startup, before any Playwright browser is launched."],"exampleFix":"# before\nconfig.LOGIN_TYPE = 'Cookie'\n\n# after\nconfig.LOGIN_TYPE = 'cookie'","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 DouYinLogin(...).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":["Exact lowercase values only; watch for trailing spaces from .env parsing","Validate before launching the browser — the error fires after the dialog pops up otherwise","Use cookie login for automated environments"],"tags":["douyin","login","configuration","valueerror"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}