{"id":"5916d25c56cfa39a","repo":"psf/requests","slug":"unable-to-find-acceptable-character-detection-depe","errorCode":null,"errorMessage":"Unable to find acceptable character detection dependency (chardet or charset_normalizer).","messagePattern":"Unable to find acceptable character detection dependency \\(chardet or charset_normalizer\\)\\.","errorType":"console","errorClass":"RequestsDependencyWarning","httpStatus":null,"severity":"warning","filePath":"src/requests/__init__.py","lineNumber":92,"sourceCode":"    major, minor, patch = int(major), int(minor), int(patch)\n    # urllib3 >= 1.21.1\n    assert major >= 1\n    if major == 1:\n        assert minor >= 21\n\n    # Check charset_normalizer for compatibility.\n    if chardet_version:\n        major, minor, patch = chardet_version.split(\".\")[:3]\n        major, minor, patch = int(major), int(minor), int(patch)\n        # chardet_version >= 3.0.2, < 8.0.0\n        assert (3, 0, 2) <= (major, minor, patch) < (8, 0, 0)\n    elif charset_normalizer_version:\n        major, minor, patch = charset_normalizer_version.split(\".\")[:3]\n        major, minor, patch = int(major), int(minor), int(patch)\n        # charset_normalizer >= 2.0.0 < 4.0.0\n        assert (2, 0, 0) <= (major, minor, patch) < (4, 0, 0)\n    else:\n        warnings.warn(\n            \"Unable to find acceptable character detection dependency \"\n            \"(chardet or charset_normalizer).\",\n            RequestsDependencyWarning,\n        )\n\n\ndef _check_cryptography(cryptography_version: str) -> None:\n    # cryptography < 1.3.4\n    try:\n        cryptography_version_list = list(map(int, cryptography_version.split(\".\")))\n    except ValueError:\n        return\n\n    if cryptography_version_list < [1, 3, 4]:\n        warning = f\"Old version of cryptography ({cryptography_version_list}) may cause slowdown.\"\n        warnings.warn(warning, RequestsDependencyWarning)\n\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/psf/requests/blob/414f0513c33883adf6f2b46901d4f0b38a455851/src/requests/__init__.py#L74-L110","documentation":"A `RequestsDependencyWarning` (not an exception) emitted at import time from `check_compatibility()` in `src/requests/__init__.py:92`. Requests uses chardet or charset_normalizer to guess a response's text encoding when the server doesn't declare one; if neither package is importable (or their versions fell outside the supported ranges checked just above), it warns that automatic character detection is unavailable. Requests still works — `response.text` just falls back to less accurate encoding handling for undeclared charsets.","triggerScenarios":"`import requests` in an environment where neither `charset_normalizer` (>=2,<4) nor `chardet` (>=3.0.2,<8) is installed — the versions are passed into `check_compatibility()` as None when import failed.","commonSituations":"Minimal/vendored installs, `pip install --no-deps requests`, aggressive dependency pruning in Docker images or lambda bundles, a broken/partial upgrade that uninstalled charset_normalizer, conda/pip mixed environments where the package landed in a different site-packages, or PyInstaller/py2exe bundles that missed the hidden import.","solutions":["Install the standard dependency: `pip install charset_normalizer` (or `pip install 'requests[use_chardet_on_py3]'` for chardet).","Reinstall requests with dependencies: `pip install --force-reinstall requests` (drop any `--no-deps` flag in your build).","Verify the active interpreter matches where you installed: `python -m pip show charset_normalizer`.","If you always know your responses' encodings, you may suppress the warning and set `response.encoding` explicitly — detection is only needed for undeclared charsets."],"exampleFix":"# before (Dockerfile)\nRUN pip install --no-deps requests\n# after\nRUN pip install requests  # pulls charset_normalizer, urllib3, idna, certifi","handlingStrategy":"fallback","validationCode":"import importlib.util\nif not (importlib.util.find_spec('charset_normalizer') or importlib.util.find_spec('chardet')):\n    raise RuntimeError('Install charset_normalizer (or chardet): pip install charset_normalizer')","typeGuard":null,"tryCatchPattern":"try:\n    import requests\nexcept ImportError as e:\n    if 'charset' in str(e) or 'chardet' in str(e):\n        sys.exit('Missing charset detection dep — pip install \"requests[use_chardet_on_py3]\" or charset_normalizer')\n    raise","preventionTips":["Install requests via pip so charset_normalizer comes in as a declared dependency — this error usually means a broken/manual install","Pin charset_normalizer (or chardet) explicitly in requirements.txt if you vendor or strip dependencies","Verify the environment at deploy time with pip check / a smoke-test import","If you never rely on detection, set response.encoding explicitly — but the import-time check still requires the package present"],"tags":["dependency","import","encoding","charset","python","requests"],"analyzedSha":"414f0513c33883adf6f2b46901d4f0b38a455851","analyzedAt":"2026-07-31T19:24:57.696Z","schemaVersion":2}