Skip to content

Commit

Permalink
First decode and encode utf-8 before falling back to chardet
Browse files Browse the repository at this point in the history
  • Loading branch information
yusra-ahmed-zz committed Aug 4, 2020
1 parent f60807f commit 29e9ec5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion exchangelib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,10 @@ def post_ratelimited(protocol, session, url, headers, data, allow_redirects=Fals
except UnicodeDecodeError:
import chardet
encoding_info = chardet.detect(data)
data = data.decode('utf-8').encode(encoding_info['encoding'])
if encoding_info['encoding'] in ['ISO-8859-1', 'Windows-1252']:
data = data.decode("utf-8").encode("utf-8")
else:
data = data.decode('utf-8').encode(encoding_info['encoding'])
try:
r = session.post(url=url,
headers=headers,
Expand Down

0 comments on commit 29e9ec5

Please sign in to comment.