AttributeError: 'dict' object has no attribute 'name'
Python · updated 2026-11-04
Raised when code reads an attribute on a plain dict. Parsed JSON (response.json(), json.loads), many database drivers' row dicts and YAML config all give dicts, which take keys in brackets, not attributes. It also appears when a function that used to return an object starts returning a dict.
Traceback (most recent call last):
File "/app/billing/sync.py", line 33, in sync_customer
email = customer.email
^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'email'Quick fix
Use key access: customer['email'] when the key must exist, customer.get('email') when it may be missing. If the code is written around attributes, convert the dict once where it comes in: a Pydantic model (Customer.model_validate(data)), a dataclass, or types.SimpleNamespace(**data).
- Check what the variable is (type(x)) and where it came from: JSON, a DB row, config.
- Replace x.field with x['field'] (or x.get('field') if it can be missing).
- Or convert once at the edge into a model with attributes and keep the rest of the code as is.
- Check for a library upgrade that changed a return type from an object to a dict (or the reverse).
- If the attribute is a dict method name (items, keys, get), you're fine; this error means the name isn't one of those.
from pydantic import BaseModel
class Customer(BaseModel):
id: str
email: str
name: str | None = None
data = response.json() # a dict
email = data["email"] # key access
nickname = data.get("name") # may be missing
customer = Customer.model_validate(data) # or convert once and use attributes
print(customer.email)Why it happens
Parsed JSON is a dict
response.json() and json.loads() return dicts and lists; dot access works in JavaScript, not in Python.
A changed return type
A helper or SDK that returned an object now returns a dict (or a raw API response), so attribute access that worked before fails.
Row and config dicts
Database cursors with dict rows, YAML or TOML config, and request.json in web frameworks all give dicts.
Serialized and loaded again
An object that was cached or sent through a queue as JSON comes back as a dict, so only the code path after a cache hit fails.
Other fixes
- For nested JSON, a Pydantic model also validates types and gives a clear error when a field is missing, instead of a KeyError deep in the code.
- The opposite error, 'X' object is not subscriptable, means code used x['field'] on an object that needs x.field.
Same error, other wording
- AttributeError: 'dict' object has no attribute 'id'
- AttributeError: 'list' object has no attribute 'get'
- AttributeError: 'str' object has no attribute 'get'
Let your coding agent catch the next one
Runheed records this error in production with the stack trace, the breadcrumbs before it and the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:
> Find the "'dict' object has no attribute" errors in production, tell me where that dict comes from, and either switch to key access or convert it into a model once where it enters the code.
Related errors
- KeyError: 'email'
- AttributeError: 'NoneType' object has no attribute 'x'
- TypeError: unhashable type: 'list'
More in Undefined, None and type errors
- TypeError: Cannot read properties of undefined (reading 'x')Node.js
- TypeError: Cannot destructure property 'id' of 'undefined' as it is undefined.Node.js
- TypeError: Cannot convert undefined or null to objectNode.js
- TypeError: items is not iterableNode.js
- TypeError: x is not a functionNode.js
- TypeError: Client is not a constructorNode.js
- ReferenceError: x is not definedNode.js
- ERR_INVALID_ARG_TYPE: The "path" argument must be of type string. Received undefinedNode.js
- TypeError: 'NoneType' object is not subscriptablePython
- TypeError: 'NoneType' object is not iterablePython
- IndexError: list index out of rangePython
- TypeError: unsupported operand type(s) for +: 'int' and 'str'Python
- ValueError: invalid literal for int() with base 10: ''Python
- TypeError: __init__() got an unexpected keyword argument 'proxies'Python
- UnboundLocalError: cannot access local variable 'total' where it is not associated with a...Python
- RuntimeError: dictionary changed size during iterationPython
- ValueError: too many values to unpack (expected 2)Python
- TypeError: 'str' object is not callablePython
References: Python docs: built-in types (dict, dict.get), Python docs: types.SimpleNamespace