INNER CODE UNIT · Python

http_request

defiprime/defiprime1 · scripts/algolia-index.py:122

def http_request(method, url, headers, body=None):
    request = urllib.request.Request(url, data=body, headers=headers, method=method)
    try:
        with urllib.request.urlopen(request, timeout=60) as response:
            return json.loads(response.read().decode("utf-8"))
    except urllib.error.HTTPError as error:
        detail = error.read().decode("utf-8", "replace")
        raise AlgoliaError(f"{method} {url} -> {error.code}: {detail}") from error


class Client:
    def __init__(self, app_id, admin_key, http):
        self.app_id = app_id
        self.http = http
        self.headers = {
            "X-Algolia-Application-Id": app_id,
            "X-Algolia-API-Key": admin_key,
            "Content-Type": "application/json",

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…