From 5855dd711f0ab9c9c4782574b8814b1e4c7f98cc Mon Sep 17 00:00:00 2001 From: jason Date: Sun, 29 Nov 2020 11:51:41 -0600 Subject: [PATCH] updated `get_encoding_from_headers` to return utf-8 if the content type is set to application/json, following RFC 4627. fixes #5667 --- requests/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requests/utils.py b/requests/utils.py index 16d57762..db67938e 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -503,6 +503,10 @@ def get_encoding_from_headers(headers): if 'text' in content_type: return 'ISO-8859-1' + if 'application/json' in content_type: + # Assume UTF-8 based on RFC 4627: https://www.ietf.org/rfc/rfc4627.txt since the charset was unset + return 'utf-8' + def stream_decode_response_unicode(iterator, r): """Stream decodes a iterator."""