{"record":{"id":"5fef0f7e22e2767c","repo":"NanmiCoder/MediaCrawler","slug":"unknown-error","errorCode":null,"errorMessage":"unknown error","messagePattern":"unknown error","errorType":"exception","errorClass":"DataFetchError","httpStatus":null,"severity":"error","filePath":"media_platform/weibo/client.py","lineNumber":100,"sourceCode":"            return response\n\n        try:\n            data: Dict = response.json()\n        except json.decoder.JSONDecodeError:\n            # issue: #771 Search API returns error 432, retry multiple times + update h5 cookies\n            utils.logger.error(f\"[WeiboClient.request] request {method}:{url} err code: {response.status_code} res:{response.text}\")\n            await self.playwright_page.goto(self._host)\n            await asyncio.sleep(2)\n            await self.update_cookies(browser_context=self.playwright_page.context)\n            raise DataFetchError(f\"get response code error: {response.status_code}\")\n\n        ok_code = data.get(\"ok\")\n        if ok_code == 0:  # response error\n            utils.logger.error(f\"[WeiboClient.request] request {method}:{url} err, res:{data}\")\n            raise DataFetchError(data.get(\"msg\", \"response error\"))\n        elif ok_code != 1:  # unknown error\n            utils.logger.error(f\"[WeiboClient.request] request {method}:{url} err, res:{data}\")\n            raise DataFetchError(data.get(\"msg\", \"unknown error\"))\n        else:  # response right\n            return data.get(\"data\", {})\n\n    async def get(self, uri: str, params=None, headers=None, **kwargs) -> Union[Response, Dict]:\n        final_uri = uri\n        if isinstance(params, dict):\n            final_uri = (f\"{uri}?\"\n                         f\"{urlencode(params)}\")\n\n        if headers is None:\n            headers = self.headers\n        return await self.request(method=\"GET\", url=f\"{self._host}{final_uri}\", headers=headers, **kwargs)\n\n    async def post(self, uri: str, data: dict) -> Dict:\n        json_str = json.dumps(data, separators=(',', ':'), ensure_ascii=False)\n        return await self.request(method=\"POST\", url=f\"{self._host}{uri}\", data=json_str, headers=self.headers)\n\n    async def pong(self) -> bool:","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/weibo/client.py#L82-L118","documentation":"Raised as DataFetchError by WeiboClient.request (media_platform/weibo/client.py:100) when the JSON body's ok field is neither 1 (success) nor 0 (known error) — an unrecognized application code. The message defaults to 'unknown error' when the payload lacks 'msg'. This branch exists because Weibo occasionally returns other ok codes (e.g. during maintenance or new anti-crawl states) and the client treats anything unexpected as a hard failure.","triggerScenarios":"A weibo API response with ok not in {0,1} — e.g. ok:2 or missing entirely with a different envelope shape; typically after Weibo-side changes, intermittent app-level states, or endpoints that return a non-standard envelope.","commonSituations":"Weibo API envelope changes after an update breaking the ok-code contract; hitting endpoints not covered by the client's assumed response shape; transient server states during high load.","solutions":["Inspect the logged res JSON to identify the actual ok value and msg, then map it in the request handler if it's a recoverable state","Add tenacity retry on the calling method for transient unknown codes","Update the client to handle the new ok code explicitly if Weibo changed the contract","Re-login if the code turns out to be session-related"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from media_platform.weibo.exception import DataFetchError\nfrom tenacity import retry, stop_after_attempt, wait_exponential\n\n@retry(stop=stop_after_attempt(3), wait=wait_exponential(min=2, max=20), reraise=True)\nasync def call_weibo(client, uri, params):\n    try:\n        return await client.get(uri, params=params)\n    except DataFetchError as e:\n        if str(e) == \"unknown error\":\n            raise  # transient/unrecognized ok code — retry with backoff\n        raise","preventionTips":["Inspect the logged ok value and msg to classify new Weibo response codes","Wrap batch crawls in per-item error handling plus bounded retries","Pin and monitor the client against Weibo API changes; update the ok-code map when envelopes change"],"tags":["weibo","api-error","unknown-code","json"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}