{"record":{"id":"671f252897e54f03","repo":"psf/requests","slug":"type-self-name-object-has-no-attribute","errorCode":null,"errorMessage":"'{type(self).__name__}' object has no attribute '{key}'","messagePattern":"'(.+?)' object has no attribute '(.+?)'","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"src/requests/structures.py","lineNumber":114,"sourceCode":"class LookupDict(dict[str, _VT]):\n    \"\"\"Dictionary lookup object.\"\"\"\n\n    name: Any\n\n    def __init__(self, name: Any = None) -> None:\n        self.name = name\n        super().__init__()\n\n    def __repr__(self) -> str:\n        return f\"<lookup '{self.name}'>\"\n\n    def __getattr__(self, key: str) -> _VT | None:\n        # We need this for type checkers to infer typing\n        # on attribute access with status_codes.py\n        if key in self.__dict__:\n            return self.__dict__[key]\n        else:\n            raise AttributeError(\n                f\"'{type(self).__name__}' object has no attribute '{key}'\"\n            )\n\n    def __getitem__(self, key: str) -> _VT | None:  # type: ignore[override]\n        # We allow fall-through here, so values default to None\n\n        return self.__dict__.get(key, None)\n\n    @overload\n    def get(self, key: str, default: None = None) -> _VT | None: ...\n\n    @overload\n    def get(self, key: str, default: _D | _VT) -> _D | _VT: ...\n\n    def get(self, key: str, default: _D | None = None) -> _VT | _D | None:\n        return self.__dict__.get(key, default)\n","sourceCodeStart":96,"sourceCodeEnd":131,"githubUrl":"https://github.com/psf/requests/blob/8068356288978c4f54661ae6f95afe0e0831885e/src/requests/structures.py#L96-L131","documentation":"Raised by LookupDict.__getattr__() when accessing an attribute that is not stored in the lookup. LookupDict is the backing class for requests.codes (the status code registry). Normal dict-style access (codes['key']) returns None for missing keys, but attribute access (codes.unknown_key) raises AttributeError.","triggerScenarios":"Accessing requests.codes.nonexistent or requests.codes.WRONG_NAME where the name isn't registered in the _codes mapping; typos in status code names; using an outdated alias that was removed in a newer version.","commonSituations":"Typo in a status code name like requests.codes.okay instead of requests.codes.ok; referencing a non-standard code not in the registry; version differences where an alias was added or removed.","solutions":["Use the correct status code name — check dir(requests.codes) or the documentation for valid names.","Use the integer status code directly (e.g. 200 instead of requests.codes.ok) for clarity and to avoid typos.","Use bracket access codes['name'] which returns None instead of raising, if you want graceful miss handling."],"exampleFix":"# before\nif resp.status_code == requests.codes.not_found:  # AttributeError\n\n# after\nif resp.status_code == 404:\n# or\nif resp.status_code == requests.codes.notfound:","handlingStrategy":"try-catch","validationCode":"valid_names = dir(requests.codes)\nif code_name not in valid_names:\n    raise ValueError(f'Unknown status code name: {code_name}')","typeGuard":null,"tryCatchPattern":"try:\n    code = getattr(requests.codes, name)\nexcept AttributeError:\n    code = None  # or fall back to integer","preventionTips":["Use integer status codes directly (200, 404, 500) instead of symbolic names to avoid typos.","Check dir(requests.codes) for valid names when unsure.","Use bracket access codes['name'] which returns None instead of raising on missing keys.","Run a quick import test after upgrading requests to catch renamed/removed aliases."],"tags":["attribute-error","lookup-dict","status-codes","api-misuse"],"backgroundTag":null,"analyzedSha":"8068356288978c4f54661ae6f95afe0e0831885e","analyzedAt":"2026-08-11T20:11:09.238Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}