AttributeError
What is AttributeError?
AttributeError: The code accesses an attribute or method that doesn't exist on an object. An AttributeError in Python means the code asked an object for an attribute or method it does not have. None.strip() is the most common example: a function returned nothing, and the next line treats the result as a string.
Frequently asked questions about AttributeError
How is AttributeError used in practice?
The error message names the type and the missing attribute, such as 'NoneType' object has no attribute 'strip'. That usually points straight at the cause. Find where the value came from and why it was not what you expected.
What should you keep in mind with AttributeError?
Often the real bug is earlier. A database lookup found no row, an API returned an empty field, or a typo in an attribute name slipped through. Handle the empty case explicitly where the value is created. Type hints with a checker like mypy catch many of these before the code runs, especially the None cases.
At a glance
| Category | Error types |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |