Skip to content

Commit

Permalink
Merge pull request #52 from nylas/yusra-ahmed/ch26621/schema-validati…
Browse files Browse the repository at this point in the history
…on-error

First decode and encode utf-8 before falling back to chardet
  • Loading branch information
yusra-ahmed-zz authored Aug 4, 2020
2 parents f60807f + 29e9ec5 commit 0a3f29b
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 0a3f29b

Please sign in to comment.