Skip to content

Commit 6e01553

Browse files
committed
corrected issue with header initialization in json helper
1 parent 418d45a commit 6e01553

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Algorithmia/client.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ class Client(object):
2424
requestSession = None
2525
bearerToken = None
2626

27-
28-
def __init__(self, apiKey = None, apiAddress = None, caCert = None, bearerToken=None):
27+
def __init__(self, apiKey=None, apiAddress=None, caCert=None, bearerToken=None):
2928
# Override apiKey with environment variable
3029
config = None
3130
self.requestSession = requests.Session()
3231
if apiKey is None and 'ALGORITHMIA_API_KEY' in os.environ:
3332
apiKey = os.environ['ALGORITHMIA_API_KEY']
3433
elif bearerToken is None and 'ALGORITHMIA_BEARER_TOKEN' in os.environ:
3534
bearerToken = os.environ['ALGORITHMIA_BEARER_TOKEN']
36-
35+
3736
self.bearerToken = bearerToken
3837
self.apiKey = apiKey
3938
if apiAddress is not None:
@@ -224,8 +223,10 @@ def postJsonHelper(self, url, input_object, parse_response_as_json=True, **query
224223
headers = {}
225224
if self.apiKey is not None:
226225
headers['Authorization'] = self.apiKey
227-
else:
228-
headers['Authorization'] = "Bearer "+ self.bearerToken
226+
elif self.bearerToken is not None:
227+
headers['Authorization'] = 'Bearer ' + self.bearerToken
228+
else:
229+
raise Exception("No authentication provided")
229230

230231
input_json = None
231232
if input_object is None:
@@ -253,8 +254,8 @@ def getHelper(self, url, **query_parameters):
253254
headers = {}
254255
if self.apiKey is not None:
255256
headers['Authorization'] = self.apiKey
256-
elif self.bearerToken is not None:
257-
headers['Authorization'] = 'Bearer '+ self.bearerToken
257+
elif self.bearerToken is not None:
258+
headers['Authorization'] = 'Bearer ' + self.bearerToken
258259
else:
259260
raise Exception("No authentication provided")
260261
return self.requestSession.get(self.apiAddress + url, headers=headers, params=query_parameters)
@@ -263,8 +264,8 @@ def getStreamHelper(self, url, **query_parameters):
263264
headers = {}
264265
if self.apiKey is not None:
265266
headers['Authorization'] = self.apiKey
266-
elif self.bearerToken is not None:
267-
headers['Authorization'] = 'Bearer '+ self.bearerToken
267+
elif self.bearerToken is not None:
268+
headers['Authorization'] = 'Bearer ' + self.bearerToken
268269
else:
269270
raise Exception("No authentication provided")
270271
return self.requestSession.get(self.apiAddress + url, headers=headers, params=query_parameters, stream=True)
@@ -273,8 +274,8 @@ def patchHelper(self, url, params):
273274
headers = {'content-type': 'application/json'}
274275
if self.apiKey is not None:
275276
headers['Authorization'] = self.apiKey
276-
elif self.bearerToken is not None:
277-
headers['Authorization'] = 'Bearer '+ self.bearerToken
277+
elif self.bearerToken is not None:
278+
headers['Authorization'] = 'Bearer ' + self.bearerToken
278279
else:
279280
raise Exception("No authentication provided")
280281
return self.requestSession.patch(self.apiAddress + url, headers=headers, data=json.dumps(params))
@@ -284,8 +285,8 @@ def headHelper(self, url):
284285
headers = {}
285286
if self.apiKey is not None:
286287
headers['Authorization'] = self.apiKey
287-
elif self.bearerToken is not None:
288-
headers['Authorization'] = 'Bearer '+ self.bearerToken
288+
elif self.bearerToken is not None:
289+
headers['Authorization'] = 'Bearer ' + self.bearerToken
289290
else:
290291
raise Exception("No authentication provided")
291292
return self.requestSession.head(self.apiAddress + url, headers=headers)
@@ -295,8 +296,8 @@ def putHelper(self, url, data):
295296
headers = {}
296297
if self.apiKey is not None:
297298
headers['Authorization'] = self.apiKey
298-
elif self.bearerToken is not None:
299-
headers['Authorization'] = 'Bearer '+ self.bearerToken
299+
elif self.bearerToken is not None:
300+
headers['Authorization'] = 'Bearer ' + self.bearerToken
300301
else:
301302
raise Exception("No authentication provided")
302303
if isJson(data):
@@ -312,8 +313,8 @@ def deleteHelper(self, url):
312313
headers = {}
313314
if self.apiKey is not None:
314315
headers['Authorization'] = self.apiKey
315-
elif self.bearerToken is not None:
316-
headers['Authorization'] = 'Bearer '+ self.bearerToken
316+
elif self.bearerToken is not None:
317+
headers['Authorization'] = 'Bearer ' + self.bearerToken
317318
else:
318319
raise Exception("No authentication provided")
319320
response = self.requestSession.delete(self.apiAddress + url, headers=headers)
@@ -375,11 +376,12 @@ def freeze(self, manifest_path, manifest_output_dir="."):
375376
required_files[i]['md5_checksum'] = md5_checksum
376377
lock_md5_checksum = md5_for_str(str(manifest_file))
377378
manifest_file['lock_checksum'] = lock_md5_checksum
378-
with open(manifest_output_dir+'/'+'model_manifest.json.freeze', 'w') as f:
379+
with open(manifest_output_dir + '/' + 'model_manifest.json.freeze', 'w') as f:
379380
json.dump(manifest_file, f)
380381
else:
381382
print("Expected to find a model_manifest.json file, none was discovered in working directory")
382383

384+
383385
def isJson(myjson):
384386
try:
385387
json_object = json.loads(myjson)

0 commit comments

Comments
 (0)