AttributeError: module 'requests' has no attribute 'get'
Python · updated 2026-11-03
Raised when code reads a name from a module object that doesn't define it. The module exists and imported fine, so the question is which file Python loaded and which version it is.
Traceback (most recent call last):
File "/app/sync.py", line 9, in fetch
r = requests.get(url, timeout=10)
^^^^^^^^^^^^
AttributeError: module 'requests' has no attribute 'get'Quick fix
Print module.__file__ right after the import. If it points into your project (a requests.py, json.py, random.py or a folder with that name), rename your file and delete its __pycache__. If it points at site-packages, check the installed version supports the name.
- Add print(requests.__file__) (with your module name) after the import and run again.
- If it is your own file, rename it and remove the matching .pyc files or __pycache__ folder.
- If it is the installed package, check its version: python -m pip show <package>.
- Look for the name in that version's docs: it may have moved, been renamed or need a submodule import (import os.path, import xml.etree.ElementTree).
- With the "partially initialized module" variant, it is a circular import: see the circular import fix.
# Which file did Python import?
python -c "import requests; print(requests.__file__)"
# Shadowing: your own requests.py hides the real package
mv requests.py http_client.py && find . -name "__pycache__" -prune -exec rm -rf {} +
# Wrong version?
python -m pip show requestsWhy it happens
A local file with the same name as a library
A script called requests.py, json.py, random.py, email.py or test.py next to your code is found before the real module, so import requests loads your file.
An older or newer version of the package
Libraries move and rename things between versions. Code written against one version breaks on another, often after a fresh install pulls a new major release.
A submodule that was never imported
import xml does not load xml.etree, and import concurrent does not load concurrent.futures. Import the submodule itself before using it.
A circular import
If the message says "partially initialized module", two modules import each other and one is used before it finished loading.
Other fixes
- Pin dependency versions in requirements.txt or a lockfile so production gets the version you tested.
- Avoid naming your own modules after standard library or popular package names.
Same error, other wording
- AttributeError: module 'json' has no attribute 'loads'
- AttributeError: module 'datetime' has no attribute 'now'
- AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import)
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 "module has no attribute" errors in production, check which file each module was loaded from and which package version is installed, and fix the shadowing file or the version mismatch.
Related errors
- ImportError: cannot import name 'x' from partially initialized module 'y' (most likely...
- ModuleNotFoundError: No module named 'x'
- AttributeError: 'NoneType' object has no attribute 'x'
References: Python docs: the module search path, Python docs: built-in exceptions (AttributeError)