#! /usr/bin/env python from http import client import logging import json def init(): logging.basicConfig(level=logging.DEBUG) with open("testApi.config.yaml", "r") as f: from yaml import safe_load config = safe_load(f) return config class apiCall: @staticmethod def call( host: str, url: str, headers: dict = None ) -> dict: import requests r = requests.get( url=f"http://{host}/{url}", # @todo The client always awaits this timeout. Even when the meaningful body is already received.params= # - I don't see any of the examples out there do it different from me. # - The browser doesn't seem to have this problem. timeout=10, headers=headers ) try: return r.json() except: logging.error(f"failed to parse json: {r.text}") if __name__ == "__main__": config = init() response = apiCall.call( host=config["host"], url="participo/api/users", # url = "participo/api", headers={ "Authorization": f"Basic {config['apiKey']}" } ) try: logging.info(json.dumps(response,indent=2)) except: logging.error(f"failed to parse to json:") logging.error(response)