import os from http.client import HTTPConnection, HTTPSConnection from urllib.parse import quote, urlsplit origin = urlsplit(os.environ["MOTANO_API_ORIGIN"]) if origin.scheme not in ("http", "https") or not origin.hostname: raise ValueError("MOTANO_API_ORIGIN must be an HTTP(S) origin") connection = HTTPSConnection if origin.scheme == "https" else HTTPConnection client = connection(origin.hostname, origin.port, timeout=20) headers = { "Authorization": "Bearer " + os.environ["MOTANO_API_KEY"], } path = "/api/v1/listings?limit=25" try: client.request("GET", path, headers=headers) response = client.getresponse() data = response.read() if not 200 <= response.status < 300: raise RuntimeError(str(response.status) + " " + data.decode("utf-8", errors="replace")) print(data.decode("utf-8")) finally: client.close()