Skip to content

Commit 5855dd7

Browse files
committed
updated get_encoding_from_headers to return utf-8 if the content type is set to application/json, following RFC 4627.
fixes #5667
1 parent d0359c9 commit 5855dd7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

requests/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ def get_encoding_from_headers(headers):
503503
if 'text' in content_type:
504504
return 'ISO-8859-1'
505505

506+
if 'application/json' in content_type:
507+
# Assume UTF-8 based on RFC 4627: https://www.ietf.org/rfc/rfc4627.txt since the charset was unset
508+
return 'utf-8'
509+
506510

507511
def stream_decode_response_unicode(iterator, r):
508512
"""Stream decodes a iterator."""

0 commit comments

Comments
 (0)