{"record":{"id":"3babe50838afb249","repo":"NanmiCoder/MediaCrawler","slug":"300012","errorCode":"300012","errorMessage":"Network connection error, please check network settings or restart","messagePattern":"Network connection error, please check network settings or restart","errorType":"exception","errorClass":"IPBlockError","httpStatus":null,"severity":"critical","filePath":"media_platform/xhs/client.py","lineNumber":180,"sourceCode":"            msg = f\"CAPTCHA appeared, request failed, Verifytype: {verify_type}, Verifyuuid: {verify_uuid}, Response: {response}\"\n            utils.logger.error(msg)\n            raise Exception(msg)\n\n        response_data: Optional[Dict] = None\n        try:\n            candidate_data = response.json()\n            if isinstance(candidate_data, dict):\n                response_data = candidate_data\n        except (TypeError, ValueError):\n            pass\n\n        response_code = (\n            str(response_data.get(\"code\"))\n            if response_data is not None and response_data.get(\"code\") is not None\n            else \"\"\n        )\n        if response_code == str(self.IP_ERROR_CODE):\n            raise IPBlockError(self.IP_ERROR_STR)\n        if response_code == str(self.SECURITY_LIMIT_CODE):\n            raise PlatformAccessError(\n                f\"XHS account security restriction, code: {self.SECURITY_LIMIT_CODE}\"\n            )\n\n        if return_response:\n            return response.text\n        data: Dict = response_data if response_data is not None else response.json()\n        if data[\"success\"]:\n            return data.get(\"data\", data.get(\"success\", {}))\n        # IP_ERROR_CODE / SECURITY_LIMIT_CODE are already handled above, before return_response.\n        elif data[\"code\"] in (self.NOTE_NOT_FOUND_CODE, self.NOTE_ABNORMAL_CODE):\n            raise NoteNotFoundError(f\"Note not found or abnormal, code: {data['code']}\")\n        else:\n            err_msg = data.get(\"msg\", None) or f\"{response.text}\"\n            raise DataFetchError(err_msg)\n\n    @staticmethod","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/xhs/client.py#L162-L198","documentation":"IPBlockError raised by XiaoHongShuClient.request when the JSON response body contains code 300012 (IP_ERROR_CODE) with the fixed message 'Network connection error, please check network settings or restart'. Despite the message, xiaohongshu emits it when the source IP is blocked/untrusted - not because of a local network outage.","triggerScenarios":"Any xhs API call from an IP on xiaohongshu's blocklist or an untrusted datacenter range; commonly appears when every request from the current IP starts returning code 300012 regardless of endpoint.","commonSituations":"Running the crawler from a cloud VM, an exhausted proxy pool, or after the previous IP got burned by aggressive crawling; ENABLE_IP_PROXY=false on a flagged host.","solutions":["Change the egress IP: enable ENABLE_IP_PROXY with a working proxy provider or run from a different network.","If already proxied, check the proxy pool - the provider may be returning dead/blacklisted IPs (see proxy/providers logs).","Wait some time (block is often temporary) before retrying from the same IP.","Catch IPBlockError and rotate the proxy, then retry the request."],"exampleFix":"// before\nres = await xhs_client.request(\"POST\", uri, payload=payload)\n// after\nfrom media_platform.xhs.exception import IPBlockError\ntry:\n    res = await xhs_client.request(\"POST\", uri, payload=payload)\nexcept IPBlockError:\n    await xhs_client._refresh_proxy_if_expired(force=True)\n    res = await xhs_client.request(\"POST\", uri, payload=payload)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from media_platform.xhs.exception import IPBlockError\nfor attempt in range(3):\n    try:\n        res = await xhs_client.request(method, uri, **kwargs)\n        break\n    except IPBlockError:\n        await xhs_client._refresh_proxy_if_expired(force=True)\n        await asyncio.sleep(30 * (attempt + 1))\nelse:\n    raise","preventionTips":["Run xhs crawls behind a rotating proxy pool (ENABLE_IP_PROXY).","Detect 300012 early with a canary request before a long crawl.","Reduce request volume per IP-hour to stay under block thresholds."],"tags":["xhs","ip-block","proxy","anti-bot"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}