From e1820d7949e635fca68e4fa72a9e0a61a693c942 Mon Sep 17 00:00:00 2001 From: Florian Best Date: Mon, 7 Mar 2022 11:45:25 +0100 Subject: [PATCH] bpo-XXXX: fix[imaplib]: call Exception with string instance Adjust the behavior similar to `authenticate()` where self.error is called with a str() instance. Especially for Python3 with strict bytes mode (-bb) this is helpful and prevents: Traceback (most recent call last): in "" self.login(email, password) File "/usr/lib/python3.7/imaplib.py", line 598, in login raise self.error(dat[-1]) imaplib.error: During handling of the above exception, another exception occurred: Traceback (most recent call last): in "" str(exc) BytesWarning: str() on a bytes instance --- Lib/imaplib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index fa4c0f8f62361a..ad64622c0be974 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -609,7 +609,7 @@ def login(self, user, password): """ typ, dat = self._simple_command('LOGIN', user, self._quote(password)) if typ != 'OK': - raise self.error(dat[-1]) + raise self.error(dat[-1].decode('UTF-8', 'replace')) self.state = 'AUTH' return typ, dat