NanmiCoder/MediaCrawler · error

Creator API response does not contain user info: {api_data}

Error message

Creator API response does not contain user info: {api_data}

What it means

Raised by TiebaExtractor.extract_creator_info_from_api (media_platform/tieba/help.py:228) as ValueError when the /c/u/pc/homeSidebarRight response has no data.user object. The extractor navigates api_data.get('data', {}).get('user', {}) and treats an empty result as a broken/expired session rather than producing an empty creator. It usually means the API responded with an error envelope (or empty data) because cookies expired or the portrait is invalid, not that the user has no profile.

Source

Thrown at media_platform/tieba/help.py:228

                note_url=note_detail.note_url,
                creator_hash=anonymize_user_id(self._api_user_link(user)),
                user_nickname=mask_nickname(user.get("name_show") or user.get("name") or ""),
                tieba_id=tieba_id,
                tieba_name=tieba_name,
                tieba_link=tieba_link,
                publish_time=utils.get_time_str_from_unix_time(item.get("time") or 0),
                note_id=note_detail.note_id,
            )
            result.append(comment)
        return result

    def extract_creator_info_from_api(self, api_data: Dict) -> TiebaCreator:
        """
        Extract Tieba creator information from current PC creator JSON API.
        """
        user = api_data.get("data", {}).get("user", {})
        if not user:
            raise ValueError(f"Creator API response does not contain user info: {api_data}")

        # 教学版:创作者个人资料不再落库,仅保留匿名哈希与脱敏昵称作内存对象。
        return TiebaCreator(
            creator_hash=anonymize_user_id(str(user.get("id", ""))),
            user_nickname=mask_nickname(str(user.get("name_show") or user.get("name") or "")),
            follows=int(user.get("concern_num") or 0),
            fans=int(user.get("fans_num") or 0),
            registration_duration=str(user.get("tb_age", "")),
        )

    @staticmethod
    def extract_creator_thread_id_list_from_api(api_data: Dict) -> List[str]:
        """
        Extract creator thread ids from current PC creator feed JSON API.
        """
        thread_ids: List[str] = []
        for item in api_data.get("data", {}).get("list", []):
            thread_info = item.get("thread_info") or {}

View on GitHub (pinned to d6f7c5bb90)

Solutions

  1. Re-login to refresh cookies and retry the creator info fetch
  2. Log the full api_data payload to see whether it is an auth error envelope or a schema change
  3. If the schema changed (field renamed/moved), update extract_creator_info_from_api to read the new path
Defensive patterns

Strategy: try-catch

Validate before calling

user = api_data.get("data", {}).get("user")
if not user:
    raise ValueError("creator API response missing data.user — likely expired cookies")

Type guard

def api_has_creator_user(api_data: dict) -> bool:
    return bool(isinstance(api_data, dict) and api_data.get("data", {}).get("user"))

Try / catch

try:
    creator = extractor.extract_creator_info_from_api(api_data)
except ValueError as e:
    if "does not contain user info" in str(e):
        await relogin_and_retry(client)  # expired session is the usual cause
    raise

Prevention

When it happens

Trigger: get_creator_info_by_url successfully fetching JSON whose 'data' or 'data.user' key is missing — e.g. error envelope {error:...}, expired-cookie response, or a portrait that no longer resolves to an account.

Common situations: Creator crawl running on stale cookies after a long session; deleted/renamed accounts; Tieba changing the homeSidebarRight response schema so the user field moved.

Related errors


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