Skip to content

Commit af19d59

Browse files
committed
Clarify dependency warning message for chardet/charset_normalizer
The warning message now clearly explains: - Which dependency has an incompatible version - What version range is supported - What action to take (install compatible version) Fixes #7284
1 parent ebf7190 commit af19d59

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

src/requests/__init__.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,36 @@ def _check_cryptography(cryptography_version):
110110
urllib3.__version__, chardet_version, charset_normalizer_version
111111
)
112112
except (AssertionError, ValueError):
113-
warnings.warn(
114-
f"urllib3 ({urllib3.__version__}) or chardet "
115-
f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
116-
"doesn't match a supported version!",
117-
RequestsDependencyWarning,
118-
)
113+
# Provide a clearer warning message that explains the issue and what to do
114+
if chardet_version is not None:
115+
warnings.warn(
116+
f"urllib3 ({urllib3.__version__}) or chardet "
117+
f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
118+
"doesn't match a supported version! "
119+
"Requests uses chardet as an optional dependency. "
120+
f"You have chardet=={chardet_version}, but requests supports chardet<6. "
121+
"Please install chardet<6 to silence this warning.",
122+
RequestsDependencyWarning,
123+
)
124+
elif charset_normalizer_version is not None:
125+
warnings.warn(
126+
f"urllib3 ({urllib3.__version__}) or chardet "
127+
f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
128+
"doesn't match a supported version! "
129+
"Requests uses charset_normalizer as an optional dependency. "
130+
f"You have charset_normalizer=={charset_normalizer_version}, but requests supports charset_normalizer<4. "
131+
"Please install charset_normalizer<4 to silence this warning.",
132+
RequestsDependencyWarning,
133+
)
134+
else:
135+
warnings.warn(
136+
f"urllib3 ({urllib3.__version__}) or chardet "
137+
f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
138+
"doesn't match a supported version! "
139+
"Please ensure you have compatible versions installed. "
140+
"See https://requests.readthedocs.io/en/latest/user/advanced/#installing-requests",
141+
RequestsDependencyWarning,
142+
)
119143

120144
# Attempt to enable urllib3's fallback for SNI support
121145
# if the standard library doesn't support SNI or the

0 commit comments

Comments
 (0)