NanmiCoder/MediaCrawler · error

Can not extract Tieba creator portrait from url: {creator_ur

Error message

Can not extract Tieba creator portrait from url: {creator_url}

What it means

Raised by BaiduTieBaClient.get_creator_info_by_url (media_platform/tieba/client.py:661) when _extract_creator_portrait(creator_url) returns a falsy value. Tieba creator homepages embed a 'portrait' identifier in the URL; the API call that fetches creator info is keyed on that portrait. If the URL doesn't match the expected pattern, the extractor returns None and this exception names the offending URL.

Source

Thrown at media_platform/tieba/client.py:661

            utils.logger.error(f"[BaiduTieBaClient.get_notes_by_tieba_name] Failed to get Tieba post list: {e}")
            raise

    async def get_creator_info_by_url(self, creator_url: str) -> TiebaCreator:
        """
        Get creator information by creator URL from current PC JSON API.
        Args:
            creator_url: Creator homepage URL

        Returns:
            TiebaCreator: Creator information
        """
        if not self.playwright_page:
            utils.logger.error("[BaiduTieBaClient.get_creator_info_by_url] playwright_page is None, cannot use browser mode")
            raise Exception("playwright_page is required for browser-based creator info fetching")

        portrait = self._extract_creator_portrait(creator_url)
        if not portrait:
            raise Exception(f"Can not extract Tieba creator portrait from url: {creator_url}")

        utils.logger.info(
            f"[BaiduTieBaClient.get_creator_info_by_url] Accessing creator info API, portrait: {portrait}"
        )

        try:
            api_data = await self._fetch_json_by_browser(
                "/c/u/pc/homeSidebarRight",
                params={
                    "portrait": portrait,
                    "un": "",
                    "subapp_type": "pc",
                    "_client_type": "20",
                },
                use_sign=True,
            )
            return self._page_extractor.extract_creator_info_from_api(api_data)

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Use the canonical creator homepage URL form that contains the portrait hash (check _extract_creator_portrait's expected pattern and match your URL to it)
  2. If you only have a username, use get_notes_by_creator(user_name, ...) instead of the URL-based API
  3. Log the failing URL and verify it opens a real Tieba user homepage in a browser
Defensive patterns

Strategy: validation

Validate before calling

from media_platform.tieba.client import BaiduTieBaClient
probe = BaiduTieBaClient.__new__(BaiduTieBaClient)
if not probe._extract_creator_portrait(creator_url):  # if extractor is instance-level, use an initialized dummy
    raise ValueError(f"Not a valid creator homepage URL: {creator_url}")

Type guard

def is_portrait_url(url: str) -> bool:
    # mirror the pattern _extract_creator_portrait expects: portrait hash present in the path/query
    return isinstance(url, str) and "tieba.baidu.com" in url and "portrait" in url

Try / catch

try:
    creator = await client.get_creator_info_by_url(creator_url)
except Exception as e:
    if "Can not extract" in str(e):
        log_bad_creator_url(creator_url)  # quarantine and continue batch
        return None
    raise

Prevention

When it happens

Trigger: Passing a creator_url that is not a Tieba user-homepage URL containing a portrait segment — e.g. 'https://tieba.baidu.com/home/main?id=...' without a portrait, a plain username URL, a forum URL, or a malformed/empty string.

Common situations: Feeding creator URLs scraped from third-party pages or hand-copied from a browser after redirects; URL format changes on Tieba's side that break the portrait regex; mixing up creator URL with post URL in crawler config.

Related errors


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