NanmiCoder/MediaCrawler · error

[ZhiHu.begin]I nvalid Login Type Currently only supported qr

Error message

[ZhiHu.begin]I nvalid Login Type Currently only supported qrcode or phone or cookies ...

What it means

ValueError raised by ZhiHuLogin.begin when config.LOGIN_TYPE is not 'qrcode', 'phone', or 'cookies'. Note that zhihu accepts 'cookies' (plural) and that its phone login is a stub ('todo implement login by mobile'), so even the accepted 'phone' value currently does nothing. Pure config-validation error.

Source

Thrown at media_platform/zhihu/login.py:75

        """
        current_cookie = await self.browser_context.cookies()
        _, cookie_dict = utils.convert_cookies(current_cookie)
        current_web_session = cookie_dict.get("z_c0")
        if current_web_session:
            return True
        return False

    async def begin(self):
        """Start login zhihu"""
        utils.logger.info("[ZhiHu.begin] Begin login zhihu ...")
        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("[ZhiHu.begin]I nvalid Login Type Currently only supported qrcode or phone or cookies ...")

    async def login_by_mobile(self):
        """Login zhihu by mobile"""
        # todo implement login by mobile

    async def login_by_qrcode(self):
        """login zhihu website and keep webdriver login state"""
        utils.logger.info("[ZhiHu.login_by_qrcode] Begin login zhihu by qrcode ...")
        qrcode_img_selector = "canvas.Qrcode-qrcode"
        # find login qrcode
        base64_qrcode_img = await utils.find_qrcode_img_from_canvas(
            self.context_page,
            canvas_selector=qrcode_img_selector
        )
        if not base64_qrcode_img:
            utils.logger.info("[ZhiHu.login_by_qrcode] login failed , have not found qrcode please check ....")
            if not base64_qrcode_img:
                sys.exit()

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Set LOGIN_TYPE to 'qrcode' or 'cookies' (plural) for zhihu.
  2. Do not use 'phone' for zhihu yet - login_by_mobile is unimplemented.
  3. Check the --lt CLI value for typos and case.

Example fix

# before
LOGIN_TYPE = "cookie"
# after
LOGIN_TYPE = "cookies"
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: LOGIN_TYPE set to an unsupported literal, or set to 'cookie' (singular, weibo-style) which fails zhihu's check; also any typo/case mismatch.

Common situations: One shared LOGIN_TYPE reused across platforms while each platform checks different literals; user expects 'phone' to work and hits the unimplemented stub afterwards.

Related errors


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