NanmiCoder/MediaCrawler · error

[WeiboLogin.begin] Invalid Login Type Currently only support

Error message

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

What it means

Raised by WeiboLogin.begin when config.LOGIN_TYPE is not one of the three supported values 'qrcode', 'phone', or 'cookie'. It is a plain ValueError from config validation, thrown before any browser session work starts.

Source

Thrown at media_platform/weibo/login.py:65

                 ):
        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
        self.weibo_sso_login_url = "https://passport.weibo.com/sso/signin?entry=miniblog&source=miniblog"

    async def begin(self):
        """Start login weibo"""
        utils.logger.info("[WeiboLogin.begin] Begin login weibo ...")
        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(
                "[WeiboLogin.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, no_logged_in_session: str) -> 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)
        if cookie_dict.get("SSOLoginState"):
            return True
        current_web_session = cookie_dict.get("WBPSESS")
        if current_web_session != no_logged_in_session:
            return True
        return False

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Set LOGIN_TYPE to exactly 'qrcode', 'phone', or 'cookie' in the weibo config (config/base_config.py or the platform config chain).
  2. If passing via CLI, check the --lt argument value for typos and case.
  3. Strip whitespace and lowercase the value before comparison if you control the config loader.

Example fix

# before
LOGIN_TYPE = "qr code"
# after
LOGIN_TYPE = "qrcode"
Defensive patterns

Strategy: validation

Validate before calling

import config
assert config.LOGIN_TYPE in {"qrcode", "phone", "cookie"}, f"bad LOGIN_TYPE: {config.LOGIN_TYPE!r}"

Type guard

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

Prevention

When it happens

Trigger: LOGIN_TYPE set to an unsupported string (e.g. 'sms', 'account', trailing whitespace like 'cookie ') or left as a placeholder in the weibo section of the config.

Common situations: Editing config/base_config.py or passing --lt with a typo; copying a config from another platform that uses a different login-type vocabulary; case mismatch ('QRCode' vs 'qrcode').

Related errors


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