AttributeError Python Origin: Application & API Last updated 14 Oct 2026

AttributeError: 'X' object has no attribute 'y'

You accessed an attribute or method that doesn’t exist on that object type.

Exact message you may see has no attribute'NoneType' object has no attribute
Seen on: Python

Meaning

The object is a different type than you think (often None, a str instead of a dict, or a library object whose API changed).

Common causes

  • Object is None ('NoneType' object has no attribute)
  • Wrong type (string vs dict)
  • Library version changed the API
  • Typo in attribute name
  • Module shadowed by a local file

⚡ Quick fix

  1. print(type(obj)) before the line
  2. Check the library version and docs
  3. Guard for None

Detailed fix by platform

Python

  1. Use dir(obj) in a debugger to see available attributes.

Code examples

Inspect the real type

python
resp = requests.get(url).json()
print(type(resp))          # <class 'list'> — not a dict, so resp.get / resp.items fail
print(dir(resp)[:20])

Module shadowing

bash
# AttributeError: module 'random' has no attribute 'randint'
ls *.py        # random.py in your project shadows the standard library
mv random.py my_random.py && rm -rf __pycache__

How to diagnose

  1. Type — print(type(obj)) right before the failing line
  2. None — Is it NoneType? Then trace why
  3. Version — Did the library rename/remove the attribute?
  4. Shadowing — Local file with the same name as a module?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

broadcast error — ValueError: operands could not be broadcast together with shapes (3,) (4,) (Python)broadcast errorCannot convert value of type — Swift: Cannot convert value of type 'X' to expected argument type 'Y' (iOS)Cannot convert value …E0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308externally-managed-environment — error: externally-managed-environment (Python)externally-managed-en…Flask app context — RuntimeError: Working outside of application context. (Python)Flask app contextImportError — ImportError: cannot import name 'x' from 'y' (Python)ImportErrorIndexError — IndexError: list index out of range (Python)IndexErrorKeyboardInterrupt — KeyboardInterrupt (script stopped with Ctrl+C) / ^C traceback (Python)KeyboardInterruptAttribute…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.