Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions ecsclient/common/token_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,25 @@ def get_new_token(self):
"""
log.info("Getting new token")
self.session.auth = (self.username, self.password)
headers = {'Accept': 'application/json'}

req = self.session.get(self.token_endpoint,
verify=self.verify_ssl,
headers={'Accept': 'application/json'},
headers=headers,
timeout=self.request_timeout)
if req.status_code == 405:
data_auth = dict(
username=self.username,
password=self.password
)

req = self.session.post(
self.token_endpoint,
json=data_auth,
headers=headers,
verify=self.verify_ssl,
timeout=self.request_timeout
)

if req.status_code == 401:
msg = 'Invalid username or password'
Expand All @@ -78,7 +92,7 @@ def get_new_token(self):
log.fatal(msg)
raise ECSClientException.from_response(req, message=msg)

self.token = req.headers['x-sds-auth-token']
self.token = req.headers.get('x-sds-auth-token', "") or req.json().get('access_token')

if self.cache_token:
log.debug("Caching token to '{0}'".format(self.token_path))
Expand Down