From e2e0a04e55cdaa997053bce23cb3d54c9e732407 Mon Sep 17 00:00:00 2001 From: Vincent Ardisson Date: Thu, 12 Mar 2020 19:02:57 +0100 Subject: [PATCH] [caissedepargne] do not compare bytes and unicode on cookies In python2, cookies from a cookiejar are bytes, but we compare them to a unicode string (unicode_literals). This is not a problem until there are non-ascii bytes. Unfortunately, sometimes the caissedepargne/palatine site returns cookies in utf-8. So we end with non-ascii bytes. In python3, it doesn't crash, but requests or the lower layers interpret cookies as latin-1 instead of utf-8, which yields a few garbled characters, but fortunately we do not care about that part of the cookie. Closes: 57830@sibi --- modules/caissedepargne/browser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/caissedepargne/browser.py b/modules/caissedepargne/browser.py index 3aeacbda75..1bddfdbf19 100644 --- a/modules/caissedepargne/browser.py +++ b/modules/caissedepargne/browser.py @@ -1156,8 +1156,10 @@ def get_profile(self): profile = Profile() if len([k for k in self.session.cookies.keys() if k == 'CTX']) > 1: del self.session.cookies['CTX'] - if 'username=' in self.session.cookies.get('CTX', ''): - profile.name = to_unicode(re.search('username=([^&]+)', self.session.cookies['CTX']).group(1)) + + ctx = to_unicode(self.session.cookies.get('CTX', '')) + if 'username=' in ctx: + profile.name = re.search('username=([^&]+)', ctx).group(1) elif 'nomusager=' in self.session.cookies.get('headerdei'): profile.name = to_unicode(re.search('nomusager=(?:[^&]+/ )?([^&]+)', self.session.cookies['headerdei']).group(1)) return profile -- GitLab