import requests from utils import apikeys import pprint from json import JSONDecodeError PP = pprint.PrettyPrinter(indent=4) APIKEY = apikeys.LUMA HEADERS = {"content-type": "application/json", "X-Api-Key": APIKEY} BASEURL = "https://api.northpass.com/v2" def get(url): try: get_response = requests.get(url, headers=HEADERS) print(f"Executed Get Request. Status code is {get_response.status_code}") except HTTPError as h: print( f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}" ) finally: json_get = get_response.json() return json_get def post(url, payload): request_subject = url.split("/")[-2:] post_response = requests.post(url, headers=HEADERS, json=payload) print(f"Executed Post Request for {str(request_subject)}.") if str(post_response.status_code).startswith('2'): print(f"Status code is {post_response.status_code}") return post_response.json() else: print(f"Status code is {post_response.status_code}") json_post = post_response.json() if json_post: return json_post else: return post_response def delete(url): try: delete_response = requests.delete(url, headers=HEADERS) print(f"Executed Delete Request. Status code is {delete_response.status_code}") except HTTPError as h: print( f"Error occurred. Here's the info: {h} and status code: {delete_response.status_code}" ) finally: return delete_response