From c94b10d7b2cdca1ca02192c9345a3dada168ba4a Mon Sep 17 00:00:00 2001 From: Jj Date: Fri, 24 Feb 2023 11:01:10 +0000 Subject: [PATCH] Store .credentials and use that for 401 handler --- src/pycrunch/elements.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pycrunch/elements.py b/src/pycrunch/elements.py index 10bb139..c4a3053 100644 --- a/src/pycrunch/elements.py +++ b/src/pycrunch/elements.py @@ -293,11 +293,10 @@ def status_401(self, r): # Do not re-attempt login if this is an API key session. return r - creds = {"email": self.session.email, "password": self.session.password} login_r = self.session.post( login_url, headers={"Content-Type": "application/json"}, - data=json.dumps(creds), + data=json.dumps(self.session.credentials), ) # Repeat the request now that we've logged in. What a hack. @@ -333,6 +332,10 @@ def __init__( self.site_url = site_url self.domain = urlparse(site_url).netloc if site_url else None self.progress_tracking = progress_tracking or DefaultProgressTracking() + if self.token: + self.credentials = {"api_key": token} + else: + self.credentials = {"email": email, "password": password} super(ElementSession, self).__init__() @property