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

**Code:** `AttributeError` · **Category:** Python · **Seen on:** Python

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/python/attributeerror)
