From 29e9ec5c779d0ca811093e8cc55c8375add7261b Mon Sep 17 00:00:00 2001 From: Yusra Date: Mon, 3 Aug 2020 21:40:49 -0700 Subject: [PATCH] First decode and encode utf-8 before falling back to chardet --- exchangelib/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exchangelib/util.py b/exchangelib/util.py index 17f6220c..bc7c8fb3 100644 --- a/exchangelib/util.py +++ b/exchangelib/util.py @@ -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,