ImportError: cannot import name 'requests' from 'botocore.vendored'
Fixes old boto3/botocore-era code that imports requests from botocore.vendored, which botocore removed. Use when upgrading boto3 breaks an import of botocore.vendored.requests. Not for general requests-library problems.
TL;DR: botocore used to ship a private copy of the requests library at botocore.vendored.requests, and it was removed. Replace from botocore.vendored import requests with a plain import requests (pip install requests if needed). Never import from botocore.vendored; it is private API.
ImportError: cannot import name 'requests' from 'botocore.vendored'Fix it
- Find the offending import: grep -rn "botocore.vendored" your codebase. Expected: one or more lines importing requests (or six, etc.) from botocore.vendored.
- Replace
from botocore.vendored import requestswithimport requests. Expected: the file no longer references botocore.vendored. - Make sure requests is installed: pip install requests. Expected: pip show requests prints a version.
- Rerun your code. Expected: the import succeeds.
When this applies
- The traceback points at an import from botocore.vendored.
- The code worked with old boto3 (pre-2019 era) and broke after an upgrade.
When it doesn't
- Your code imports plain
requestsand that fails: you just need pip install requests. - The failing import is from some other vendored path: same principle, stop importing privates.
Compatibility
- boto3/botocore >= 1.13 (when the vendored copy was dropped). requests >= 2.20.
Why it happens
botocore once vendored third-party libraries so installs were self-contained. Vendoring was dropped to reduce security and maintenance burden, which broke anyone importing those private copies directly.
Edge cases
- botocore.vendored also used to carry six and python-dateutil shims; same fix: install the real package.
- If a dependency (not your code) does this import, upgrade that dependency to a version that no longer uses botocore.vendored.