MCPcopy Index your code
hub / github.com/algorithmiaio/algorithmia-python / postJsonHelper

Method postJsonHelper

Algorithmia/client.py:233–268  ·  view source on GitHub ↗
(self, url, input_object, parse_response_as_json=True, retry=False, **query_parameters)

Source from the content-addressed store, hash-verified

231
232 # Used internally to post json to the api and parse json response
233 def postJsonHelper(self, url, input_object, parse_response_as_json=True, retry=False, **query_parameters):
234 headers = {}
235 if self.apiKey is not None:
236 headers['Authorization'] = self.apiKey
237 elif self.bearerToken is not None:
238 headers['Authorization'] = 'Bearer ' + self.bearerToken
239
240 input_json = None
241 if input_object is None:
242 input_json = json.dumps(None).encode('utf-8')
243 headers['Content-Type'] = 'application/json'
244 elif isinstance(input_object, six.string_types):
245 input_json = input_object.encode('utf-8')
246 headers['Content-Type'] = 'text/plain'
247 elif isinstance(input_object, bytearray) or isinstance(input_object, bytes):
248 input_json = bytes(input_object)
249 headers['Content-Type'] = 'application/octet-stream'
250 else:
251 input_json = json.dumps(input_object).encode('utf-8')
252 headers['Content-Type'] = 'application/json'
253
254 response = self.requestSession.post(self.apiAddress + url, data=input_json, headers=headers,
255 params=query_parameters)
256 if 200 <= response.status_code <= 299:
257 if parse_response_as_json:
258 response = response.json()
259 if 'error' in response:
260 raise raiseAlgoApiError(response)
261 else:
262 return response
263 else:
264 return response
265 elif retry:
266 return self.postJsonHelper(url, input_object, parse_response_as_json, False, **query_parameters)
267 else:
268 raise raiseAlgoApiError(response)
269
270 # Used internally to http get a file
271 def getHelper(self, url, **query_parameters):

Callers 10

create_userMethod · 0.95
create_orgMethod · 0.95
set_secretMethod · 0.80
createMethod · 0.80
publishMethod · 0.80
compileMethod · 0.80
pipeMethod · 0.80
_postRawOutputMethod · 0.80
_postVoidOutputMethod · 0.80
createMethod · 0.80

Calls 1

raiseAlgoApiErrorFunction · 0.90

Tested by

no test coverage detected