soimort/you-get · error · TypeError

URL does not conform to specifications, Support column and q

Error message

URL does not conform to specifications, Support column and question only.Example URL: https://zhuanlan.zhihu.com/p/51669862 or https://www.zhihu.com/question/267782048/answer/490720324

What it means

First of two TypeError guards in zhihu_download (src/you_get/extractors/zhihu.py:13). It rejects URLs whose slash-split path list is too short to be either a Zhihu column or a question/answer page. Note the condition uses `and` (len<3 AND len<6), so in practice it only fires for very short paths like 'https://zhuanlan.zhihu.com' split into fewer than 3 parts.

Source

Thrown at src/you_get/extractors/zhihu.py:13

#!/usr/bin/env python

__all__ = ['zhihu_download', 'zhihu_download_playlist']

from ..common import *
import json


def zhihu_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
    paths = url.split("/")
    # question or column
    if len(paths) < 3 and len(paths) < 6:
        raise TypeError("URL does not conform to specifications, Support column and question only."
                        "Example URL: https://zhuanlan.zhihu.com/p/51669862 or "
                        "https://www.zhihu.com/question/267782048/answer/490720324")

    if ("question" not in paths or "answer" not in paths) and "zhuanlan.zhihu.com" not in paths:
        raise TypeError("URL does not conform to specifications, Support column and question only."
                        "Example URL: https://zhuanlan.zhihu.com/p/51669862 or "
                        "https://www.zhihu.com/question/267782048/answer/490720324")

    html = get_html(url, faker=True)
    title = match1(html, r'data-react-helmet="true">(.*?)</title>')
    for index, video_id in enumerate(matchall(html, [r'<a class="video-box" href="\S+video/(\d+)"'])):
        try:
            video_info = json.loads(
                get_content(r"https://lens.zhihu.com/api/videos/{}".format(video_id), headers=fake_headers))
        except json.decoder.JSONDecodeError:
            log.w("Video id not found:{}".format(video_id))
            continue

View on GitHub (pinned to 049548f3f3)

Solutions

  1. Pass a complete supported URL: a column https://zhuanlan.zhihu.com/p/51669862 or a question/answer https://www.zhihu.com/question/267782048/answer/490720324.
  2. If constructing URLs programmatically, assert the path contains the required segments before calling.
  3. Validate the URL shape upstream (regex or urlparse) so the library guard never fires.
  4. Note the guard itself looks buggy (len(paths)<3 and len(paths)<6 is equivalent to len<3); if you maintain this fork, fix to `or` — but do not rely on that for correctness.

Example fix

# before
zhihu_download('https://zhuanlan.zhihu.com')  # TypeError

# after
zhihu_download('https://zhuanlan.zhihu.com/p/51669862')
Defensive patterns

Strategy: validation

Validate before calling

import re

ZHIHU_OK = re.compile(
    r'^https?://(zhuanlan\.zhihu\.com/p/\d+|www\.zhihu\.com/question/\d+/answer/\d+)')

def is_supported_zhihu_url(url):
    return bool(ZHIHU_OK.match(url))

Type guard

null

Try / catch

try:
    zhihu_download(url)
except TypeError as e:
    raise ValueError('Unsupported Zhihu URL (need column or question/answer): %s' % url) from e

Prevention

When it happens

Trigger: Calling zhihu_download with a bare domain or truncated URL such as 'https://zhuanlan.zhihu.com' or 'https://www.zhihu.com', producing a paths list shorter than 3 elements after url.split('/').

Common situations: User typos or truncates the URL; a script builds the URL from a template and drops the path segment; playlist walker passes a malformed constructed URL. The companion guard at line 18 catches well-formed but unsupported URLs (missing 'question'+'answer' or 'zhuanlan.zhihu.com').

Related errors


AI-assisted analysis of soimort/you-get@049548f3f3 (2026-08-15). Data as JSON: /api/errors/2e4bfa1203501755. Report an issue: GitHub.