{"record":{"id":"1a5589c7f93d8de6","repo":"MetaCubeX/mihomo","slug":"user-not-found","errorCode":null,"errorMessage":"User not found.","messagePattern":"User not found\\.","errorType":"exception","errorClass":"UserNotFound","httpStatus":404,"severity":"error","filePath":"mihomo/client.py","lineNumber":93,"sourceCode":"\n        async with aiohttp.ClientSession() as session:\n            async with session.get(url, params=params) as response:\n                match response.status:\n                    case 200:\n                        return await response.json(encoding=\"utf-8\")\n                    case 400:\n                        try:\n                            data = await response.json(encoding=\"utf-8\")\n                        except:\n                            raise InvalidParams()\n                        else:\n                            if isinstance(data, dict) and (\n                                detail := data.get(\"detail\")\n                            ):\n                                raise InvalidParams(detail)\n                            raise InvalidParams()\n                    case 404:\n                        raise UserNotFound()\n                    case _:\n                        raise HttpRequestError(response.status, str(response.reason))\n\n    async def fetch_user(\n        self,\n        uid: int,\n        *,\n        replace_icon_name_with_url: bool = False,\n    ) -> StarrailInfoParsed:\n        \"\"\"\n        Fetches user data from the API.\n\n        Args:\n            - uid (`int`): The user ID.\n            - replace_icon_name_with_url (`bool`): Whether to replace icon names with asset URLs.\n\n        Returns:\n            StarrailInfoParsed: The parsed user data from mihomo API.","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/MetaCubeX/mihomo/blob/008b91bfe8c0e2daca0ab69061efd9ea1ad71bd2/mihomo/client.py#L75-L111","documentation":"UserNotFound is raised at mihomo/client.py:93 when api.mihomo.me answers HTTP 404 for the requested UID. It means the UID is syntactically acceptable but the API has no showcase data for it — most often because the player's public battle-record/showcase is hidden or the UID simply doesn't exist. The exception carries the fixed message 'User not found.' (mihomo/errors.py:36) with no extra payload.","triggerScenarios":"Calling fetch_user/fetch_user_v1 with a well-formed 9-digit UID that does not exist; the player has 'Show battle record' / showcase visibility disabled in-game; the UID region is correct in form but the account was deleted or the data cache has no entry.","commonSituations":"Users copying their account ID instead of the in-game UID; players who never enabled the public showcase (the mihomo API can only serve data when the battle record is public); recently created accounts whose data the API hasn't indexed yet; transposed digits in a hardcoded UID.","solutions":["Double-check the UID — it must be the in-game 9-digit UID shown on the profile, not the HoYoverse account ID.","Ask the player to enable 'Show character details' / public battle record in game settings, then retry.","Catch UserNotFound and treat it as a distinct, user-facing condition (unknown player) rather than a generic failure.","If the UID is definitely valid and public, wait a few minutes — the API caches aggressively — and retry once."],"exampleFix":"// before\ndata = await client.fetch_user(uid)  # raises UserNotFound, crashes app\n\n// after\nfrom mihomo.errors import UserNotFound\ntry:\n    data = await client.fetch_user(uid)\nexcept UserNotFound:\n    return \"Player not found — check the UID and enable public battle record.\"","handlingStrategy":"try-catch","validationCode":"# Cannot fully prevent: 404 depends on server-side data.\n# Cheap pre-check: format-validate the UID.\ndef looks_like_uid(uid: int | str) -> bool:\n    return str(uid).isdigit() and len(str(uid)) == 9","typeGuard":null,"tryCatchPattern":"from mihomo.errors import UserNotFound, InvalidParams, HttpRequestError\ntry:\n    data = await client.fetch_user(uid)\nexcept UserNotFound:\n    reply(\"Player not found — check the UID and enable the public battle record.\")\nexcept InvalidParams as e:\n    reply(f\"Bad request: {e.message}\")\nexcept HttpRequestError as e:\n    reply(f\"API error {e.status}: {e.reason}\")","preventionTips":["Distinguish UserNotFound from generic errors in your handler; it is an expected, user-facing outcome.","Tell users to enable 'public battle record' in-game before querying their profile.","Pre-validate UID format to catch typos before spending a request.","Cache negative results briefly so repeated lookups of a dead UID don't hammer the API."],"tags":["python","mihomo","http-404","uid","star-rail"],"backgroundTag":"http-404-not-found","analyzedSha":"008b91bfe8c0e2daca0ab69061efd9ea1ad71bd2","analyzedAt":"2026-08-27T19:16:11.578Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}