{"record":{"id":"ab66db21eb53f62f","repo":"MetaCubeX/mihomo","slug":"invalid-parameters","errorCode":null,"errorMessage":"Invalid parameters","messagePattern":"Invalid parameters","errorType":"exception","errorClass":"InvalidParams","httpStatus":400,"severity":"error","filePath":"mihomo/client.py","lineNumber":85,"sourceCode":"        Raises:\n            HttpRequestError: If the HTTP request fails.\n            InvalidParams: If the API request contains invalid parameters.\n            UserNotFound: If the requested user is not found.\n\n        \"\"\"\n        url = self.BASE_URL + \"/\" + str(uid)\n        params.update({\"lang\": language.value})\n\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        \"\"\"","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/MetaCubeX/mihomo/blob/008b91bfe8c0e2daca0ab69061efd9ea1ad71bd2/mihomo/client.py#L67-L103","documentation":"InvalidParams is raised by MihomoAPI.request (mihomo/client.py:85) when the remote mihomo API responds with HTTP 400 and the body either is not valid JSON or is JSON without a 'detail' key. It means the request parameters — typically the UID or the lang query parameter — were rejected by api.mihomo.me. This is a parameter-validation error from the upstream service, surfaced as an exception without any detail message.","triggerScenarios":"Calling fetch_user or fetch_user_v1 with a malformed UID (empty string, non-numeric characters, wrong length) so the API returns 400 with a non-JSON or detail-less body; also when the Language enum value sent as the lang param is not accepted by the endpoint, or the version=v1 param combination is rejected.","commonSituations":"Passing a UID taken from user input without validating it (e.g. trimming mistakes, embedded spaces); using an outdated library version whose Language values no longer match the API; sending a 9-digit non-StarRail UID; API contract changes where 400 responses switch from JSON to plain text (Cloudflare/proxy error pages), which trips the bare except at client.py:84.","solutions":["Validate the UID before calling fetch_user: it must be a 9-digit numeric Star Rail UID (str(uid).isdigit() and len == 9).","Inspect str(exc) / exc.message — a sibling raise at client.py:90 includes the API's 'detail' text which pinpoints the bad parameter.","Verify the Language passed to MihomoAPI(language=...) is one of the supported enum members and not a raw string.","If the 400 body is HTML (proxy/WAF), retry against the API later or from a different network; check api.mihomo.me status."],"exampleFix":"// before\ndata = await client.fetch_user(int(user_input))\n\n// after\nuid = int(user_input)\nif not (100000000 <= uid <= 999999999):\n    raise ValueError(f\"Invalid Star Rail UID: {uid}\")\ndata = await client.fetch_user(uid)","handlingStrategy":"validation","validationCode":"def is_valid_uid(uid: int | str) -> bool:\n    s = str(uid)\n    return s.isdigit() and len(s) == 9 and 100000000 <= int(s) <= 999999999\n\nif not is_valid_uid(uid):\n    raise ValueError(f\"Invalid Star Rail UID: {uid!r}\")\ndata = await client.fetch_user(uid)","typeGuard":null,"tryCatchPattern":"from mihomo.errors import InvalidParams\ntry:\n    data = await client.fetch_user(uid)\nexcept InvalidParams as e:\n    log.warning(\"Bad parameters for uid=%s: %s\", uid, e.message)","preventionTips":["Validate UID format (9 digits, numeric) before any API call.","Pass Language enum members, never raw strings, to MihomoAPI().","Upgrade the mihomo package when the API adds/removes supported languages.","Never construct params yourself for fetch_user_v1; let the library set version=v1."],"tags":["python","mihomo","http-400","parameter-validation","star-rail"],"backgroundTag":"http-400-bad-request","analyzedSha":"008b91bfe8c0e2daca0ab69061efd9ea1ad71bd2","analyzedAt":"2026-08-27T19:16:11.578Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}