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).

  1. Check what the variable is (type(x)) and where it came from: JSON, a DB row, config.
  2. Replace x.field with x['field'] (or x.get('field') if it can be missing).
  3. Or convert once at the edge into a model with attributes and keep the rest of the code as is.
  4. Check for a library upgrade that changed a return type from an object to a dict (or the reverse).
  5. If the attribute is a dict method name (items, keys, get), you're fine; this error means the name isn't one of those.
python
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.

Plans from $29/moSee what your agent readsSee the setupCancel any time from the billing portal

Related errors

More in Undefined, None and type errors

References: Python docs: built-in types (dict, dict.get), Python docs: types.SimpleNamespace