Skip to content

Commit

Permalink
Merge pull request #81 from Crunch-io/no-email-warning
Browse files Browse the repository at this point in the history
Store .credentials and use that for 401 handler
  • Loading branch information
jjdelc authored Feb 27, 2023
2 parents 80e1ddd + c94b10d commit 28fd1c2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pycrunch/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 28fd1c2

Please sign in to comment.