def login_for_jwt(self):
try:
session = requests.Session()
session.headers.update({'content-type':'application/json', 'accept': 'application/json'})
password_prompt = bytes_to_native_str(b"Password :")
if self.id_provider == 'udacity':
print("Udacity Login required.")
email = input('Email :')
password = getpass.getpass(password_prompt)
udacity_login(session, self.root_url, email, password)
elif self.id_provider == 'gt':
print("GT Login required.")
username = input('Username :')
password = getpass.getpass(password_prompt)
gt_login(session, self.root_url, username, password)
elif self.id_provider == 'developer':
print("Developer Login required.")
username = input('Username :')
developer_login(session, self.root_url, username)
except requests.exceptions.HTTPError as e:
if e.response.status_code == 403:
raise NelsonAuthenticationError("Authentication failed")
else:
raise e
r = session.post(self.root_url + '/auth_tokens')
r.raise_for_status()
jwt = r.json()['auth_token']
return jwt
#Helper functions for logins
评论列表
文章目录