in camera-sdk/iotccsdk/ipcprovider.py [0:0]
def __send_request(self, method, path, payload, params):
"""
private method to send requests to QMMF IPC webserver.
Parameters
----------
method : str
Method type for call must be in `ALL_METHODS`
path : str
QMMF IPC webserver API.
payload : str
JSON payload for the `path` API.
params : str
Params for the `path` API.
Returns
-------
response: dict
response from the request
Raises
------
ConnectionError
When response is malformed
Exception
Any exception that occurs during the request.
"""
if (method.lower() not in ALL_METHODS):
raise ValueError("Method must be in %s" % ALL_METHODS)
url = self._build_url(path)
headers = {"Cookie": self._session_token}
self.logger.info("API: %s data %s" % (url, payload))
try:
with requests.session() as mysession:
if method.lower() == POST_METHOD:
response = mysession.post(
url, data=json.dumps(payload), headers=headers, params=params)
else:
response = mysession.get(
url, data=json.dumps(payload), headers=headers, params=params)
if response.status_code != requests.codes.ok:
self.logger.info("RESPONSE: %s" % response.text)
result = response.json()
if "status" not in result and "Status" not in result:
raise requests.ConnectionError(
"Call with method: %s to: %s returned malformed response: %s" %
(method, url, response))
return result
except Exception as e:
self.logger.exception(e)
raise