@@ -329,7 +329,7 @@ def __build_auth_header():
329
329
rsps = requests .post (host , data = json .dumps (rqst ), headers = hdrs , timeout = request_timeout ).json ()
330
330
ps_refresh_token = rsps ["refresh" ]
331
331
ps_access_token = rsps ["access" ]
332
- ps_token_exp = time .time () + (rsps ["access_lifetime" ] / 2 )
332
+ ps_token_exp = time .time () + (float ( rsps ["access_lifetime" ]) / 2 )
333
333
# Build Authentication Header
334
334
headers = {'Authorization' : 'Bearer ' + ps_access_token }
335
335
return headers
@@ -411,14 +411,14 @@ def source (api, parm={}, stream=False, callbacks={}, path="/source"):
411
411
for c in __callbacks :
412
412
if c not in callbacks :
413
413
callbacks [c ] = __callbacks [c ]
414
- # Construct Request URL and Authorization
415
- if service_org :
416
- url = 'https://%s.%s%s/%s' % (service_org , service_url , path , api )
417
- headers = __build_auth_header ()
418
- else :
419
- url = 'http://%s%s/%s' % (service_url , path , api )
420
414
# Attempt Request
421
415
try :
416
+ # Construct Request URL and Authorization
417
+ if service_org :
418
+ url = 'https://%s.%s%s/%s' % (service_org , service_url , path , api )
419
+ headers = __build_auth_header ()
420
+ else :
421
+ url = 'http://%s%s/%s' % (service_url , path , api )
422
422
# Perform Request
423
423
if not stream :
424
424
data = requests .get (url , data = rqst , headers = headers , timeout = request_timeout )
@@ -566,9 +566,9 @@ def update_available_servers (desired_nodes=None):
566
566
567
567
# Update number of nodes
568
568
if type (desired_nodes ) == int :
569
- host = "https://ps." + service_url + "/api/desired_org_num_nodes/" + service_org + "/" + str (desired_nodes )
569
+ host = "https://ps." + service_url + "/api/desired_org_num_nodes/" + service_org + "/" + str (desired_nodes ) + "/"
570
570
headers = __build_auth_header ()
571
- rsps = requests .get (host , headers = headers , timeout = request_timeout ). json ( )
571
+ rsps = requests .put (host , headers = headers , timeout = request_timeout )
572
572
rsps .raise_for_status ()
573
573
574
574
# Get number of nodes currently registered
@@ -640,10 +640,13 @@ def authenticate (ps_organization, ps_username=None, ps_password=None):
640
640
headers = {'Content-Type' : 'application/json' }
641
641
try :
642
642
api = "https://" + ps_url + "/api/org_token/"
643
- rsps = requests .post (api , data = json .dumps (rqst ), headers = headers , timeout = request_timeout ).json ()
643
+ print ("cred" , api , ps_username , ps_password , ps_organization )
644
+ rsps = requests .post (api , data = json .dumps (rqst ), headers = headers , timeout = request_timeout )
645
+ rsps .raise_for_status ()
646
+ rsps = rsps .json ()
644
647
ps_refresh_token = rsps ["refresh" ]
645
648
ps_access_token = rsps ["access" ]
646
- ps_token_exp = time .time () + (rsps ["access_lifetime" ] / 2 )
649
+ ps_token_exp = time .time () + (float ( rsps ["access_lifetime" ]) / 2 )
647
650
login_status = True
648
651
except :
649
652
logger .error ("Unable to authenticate user %s to %s" % (ps_username , api ))
0 commit comments