psf/requests · warning · RequestsDependencyWarning

urllib3 ({urllib3.__version__}) or chardet ({chardet_version

Error message

urllib3 ({urllib3.__version__}) or chardet ({chardet_version})/charset_normalizer ({charset_normalizer_version}) doesn't match a supported version!

What it means

This is a RequestsDependencyWarning emitted at `import requests` time. On import, requests runs `check_compatibility()` (src/requests/__init__.py:60) which asserts that urllib3 is >= 1.21.1 (and not a 'dev' git build), chardet is >= 3.0.2 and < 8.0.0, or charset_normalizer is >= 2.0.0 and < 4.0.0. If any assert fails or a version string can't be parsed to integers (ValueError), the except at line 118 converts it into this warning rather than crashing, since requests may still work but is running against an untested dependency combination.

Source

Thrown at src/requests/__init__.py:119

    try:
        cryptography_version_list = list(map(int, cryptography_version.split(".")))
    except ValueError:
        return

    if cryptography_version_list < [1, 3, 4]:
        warning = f"Old version of cryptography ({cryptography_version_list}) may cause slowdown."
        warnings.warn(warning, RequestsDependencyWarning)


# Check imported dependencies for compatibility.
try:
    check_compatibility(
        urllib3.__version__,
        chardet_version,
        charset_normalizer_version,
    )
except (AssertionError, ValueError):
    warnings.warn(
        f"urllib3 ({urllib3.__version__}) or chardet "
        f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
        "doesn't match a supported version!",
        RequestsDependencyWarning,
    )

# Attempt to enable urllib3's fallback for SNI support
# if the standard library doesn't support SNI or the
# 'ssl' library isn't available.
try:
    try:
        import ssl
    except ImportError:
        ssl = None

    if not getattr(ssl, "HAS_SNI", False):
        from urllib3.contrib import pyopenssl

View on GitHub ↗ (pinned to 414f0513c3)

Solutions

  1. Upgrade requests to the latest release so its supported version ranges include your installed deps: pip install -U requests
  2. Reinstall the checked dependencies into requests' supported ranges: pip install -U 'urllib3>=1.21.1' 'charset_normalizer>=2,<4'
  3. Verify what is actually installed in the active environment: pip show requests urllib3 charset_normalizer chardet — and remove duplicate/conflicting copies (e.g. pip uninstall chardet if both detectors are present at odd versions)
  4. Avoid pre-release or git installs of urllib3/charset_normalizer (non-numeric version strings trigger this warning); pin release versions instead
  5. If the environment is a mixed conda+pip install, recreate it or reinstall requests and its deps with a single package manager to eliminate shadowed packages

Example fix

# before (requirements.txt) — mismatched pins trigger RequestsDependencyWarning
requests==2.25.1
urllib3==2.2.0

# after — let requests own its dependency range
requests>=2.32.0
# (urllib3 and charset_normalizer resolved by requests' own constraints)
Defensive patterns

Strategy: validation

Validate before calling

# Check dependency compatibility before importing requests in app startup
import importlib.metadata as md

def check_requests_deps():
    urllib3_v = md.version('urllib3')
    major, minor, _ = (urllib3_v.split('.') + ['0'])[:3]
    assert int(major) in (1, 2), f'unsupported urllib3 {urllib3_v}'
    try:
        cn = md.version('charset_normalizer')
    except md.PackageNotFoundError:
        cn = None
    try:
        ch = md.version('chardet')
    except md.PackageNotFoundError:
        ch = None
    assert cn or ch, 'need charset_normalizer or chardet installed'

check_requests_deps()

Try / catch

import warnings
try:
    with warnings.catch_warnings():
        warnings.simplefilter('error')  # surface RequestsDependencyWarning as an error
        import requests
except Warning as w:
    # Incompatible urllib3/chardet/charset_normalizer versions
    raise SystemExit(f'requests dependency mismatch: {w} — pin compatible versions (pip install -U requests)')

Prevention

When it happens

Trigger: Emitted the first time `import requests` runs in a process when: urllib3.__version__ is below 1.21.1 or reports a non-numeric/dev version (e.g. '2.0.0a1', git checkout); chardet.__version__ is outside [3.0.2, 8.0.0); charset_normalizer.__version__ is outside [2.0.0, 4.0.0); or any of those version strings contains non-integer components so int() raises ValueError during parsing.

Common situations: Upgrading urllib3 or charset_normalizer independently of requests (e.g. `pip install -U urllib3` pulled a major version an old requests doesn't recognize); an old pinned requests in a requirements file combined with newer transitive deps; conda/pip mixed environments with mismatched packages; installing urllib3 or charset_normalizer from git or a pre-release (alpha/beta version strings fail int parsing); system Python with distro-patched version strings; Lambda/Docker layers shipping their own urllib3 alongside a different requests.

Related errors


AI-assisted analysis of psf/requests@414f0513c3 (2026-07-31). Data as JSON: /data/errors/2a4fd7c1468983b8.json. Report an issue: GitHub ↗.