NanmiCoder/MediaCrawler · error · ValueError

[KuaishouLogin.begin] Invalid Login Type Currently only supp

Error message

[KuaishouLogin.begin] Invalid Login Type Currently only supported qrcode or phone or cookie ...

What it means

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.

Source

Thrown at media_platform/kuaishou/login.py:59

                 cookie_str: str = ""
                 ):
        config.LOGIN_TYPE = login_type
        self.browser_context = browser_context
        self.context_page = context_page
        self.login_phone = login_phone
        self.cookie_str = cookie_str

    async def begin(self):
        """Start login xiaohongshu"""
        utils.logger.info("[KuaishouLogin.begin] Begin login kuaishou ...")
        if config.LOGIN_TYPE == "qrcode":
            await self.login_by_qrcode()
        elif config.LOGIN_TYPE == "phone":
            await self.login_by_mobile()
        elif config.LOGIN_TYPE == "cookie":
            await self.login_by_cookies()
        else:
            raise ValueError("[KuaishouLogin.begin] Invalid Login Type Currently only supported qrcode or phone or cookie ...")

    @retry(stop=stop_after_attempt(600), wait=wait_fixed(1), retry=retry_if_result(lambda value: value is False))
    async def check_login_state(self) -> bool:
        """
            Check if the current login status is successful and return True otherwise return False
            retry decorator will retry 20 times if the return value is False, and the retry interval is 1 second
            if max retry times reached, raise RetryError
        """
        current_cookie = await self.browser_context.cookies()
        _, cookie_dict = utils.convert_cookies(current_cookie)
        kuaishou_pass_token = cookie_dict.get("passToken")
        if kuaishou_pass_token:
            return True
        return False

    async def login_by_qrcode(self):
        """login kuaishou website and keep webdriver login state"""
        utils.logger.info("[KuaishouLogin.login_by_qrcode] Begin login kuaishou by qrcode ...")

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Set config.LOGIN_TYPE to exactly 'qrcode', 'phone', or 'cookie' (lowercase, no whitespace) in the config source feeding config.LOGIN_TYPE
  2. Check the actual value at runtime (print/log config.LOGIN_TYPE) to spot casing or trailing-space issues
  3. If you need another type, implement a login_by_* method and extend the elif chain in KuaishouLogin.begin

Example fix

# before
LOGIN_TYPE=QRCode  # or 'sms'

# after
LOGIN_TYPE=qrcode
Defensive patterns

Strategy: validation

Validate before calling

import config
assert config.LOGIN_TYPE in {"qrcode", "phone", "cookie"}, (
    f"LOGIN_TYPE must be qrcode|phone|cookie, got {config.LOGIN_TYPE!r}"
)

Type guard

def is_valid_kuaishou_login_type(value: str) -> bool:
    return isinstance(value, str) and value.strip().lower() in {"qrcode", "phone", "cookie"}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of NanmiCoder/MediaCrawler@d6f7c5bb90 (2026-08-15). Data as JSON: /api/errors/eba7bda2d92628d6. Report an issue: GitHub.