Skip to content
Myr

potentially fixes #338

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This attempts to fix an issue where encoding of a string might fail when the encoding is set to some unknown format. Here we attempt to catch the LookupException and subsequently blindly encode the string one final time. That is we call str() over response.content without specifying an encoding. This may still fail in certain cases but does properly handle the case of #338 by returning the expected string.

authored by Max Countryman · committed by Max Countryman · parent 6562137 · Browse files · 1 file+3 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+3 added−0 removed

  • other:+3 added−0 removed

1 file+3 added−0 removed

modified:requests/models.py+3 added
786 unmodified lines
787788 # Decode unicode from given encoding.789 try:790 content = str(self.content, encoding, errors='replace')791 except LookupError:792 # try blindly encoding793 content = str(self.content, errors='replace')794 except (UnicodeError, TypeError):795 pass796797 return content
22 unmodified lines