def get_headers(endpoint, message_type, action): global omf_version msg_headers = { "x-requested-with": "xmlhttprequest", 'messagetype': message_type, 'action': action, 'messageformat': 'JSON', 'omfversion': omf_version } if endpoint['UseCompression'] == "gzip": msg_headers["compression"] = "gzip" authorization = auth.get_auth_header(endpoint) if authorization: msg_headers["authorization"] = authorization return msg_headers
def check_last_adh_val(endpoint): time.sleep(10) msg_headers = auth.sanitize_headers( {"authorization": auth.get_auth_header(endpoint)}) url = endpoint['OmfEndpoint'].split('/omf')[0] + \ '/streams/Tank1Measurements/data/last' response = requests.get(url, headers=msg_headers, verify=endpoint["VerifySSL"]) # response code in 200s if the request was successful! if response.status_code < 200 or response.status_code >= 300: print(msg_headers) response.close() print( f'Response from was bad. message: {response.status_code} {response.text}.' ) print() raise Exception( f'OMF message was unsuccessful, {response.status_code}:{response.text}' )
def get(path, params=None): requests.get(f'{base_url}/{path}', params=params, header=get_auth_header()) if response.status_code not in [200, 201, 204]: raise exc.ResponseException(response) return response.json()
def put(path, data=None): requests.put(f'{base_url}/{path}', json=data, header=get_auth_header()) if response.status_code not in [200, 201, 204]: raise exc.ResponseException(response) return response.json()
def upload(path, data = None): res = requests.post(f'{base_url}/{path}', json = data, headers = get_auth_header()) #if res.status_code not in [200, 201, 204]: # raise exc.ResponseException(res) return res.json()
def status(): res = requests.get(f'{base_url}/{path}', params = params, headers = get_auth_header()) #if res.status_code not in [200, 201, 204]: #raise exc.ResponseException(res) return res.json()