INNER CODE UNIT · Python

api

rignaneseleo/SlimSocial-for-Facebook · .github/scripts/crowdin_pretranslate.py:26

def api(path, method="GET", body=None, raw=None, filename=None, ok_errors=()):
    global LAST_ERROR
    headers = {"Authorization": "Bearer " + TOKEN}
    data = None
    if raw is not None:
        data = raw
        headers["Content-Type"] = "application/octet-stream"
        headers["Crowdin-API-FileName"] = filename
    elif body is not None:
        data = json.dumps(body).encode()
        headers["Content-Type"] = "application/json"
    req = urllib.request.Request(BASE + path, method=method, headers=headers, data=data)
    for attempt in range(4):
        try:
            with urllib.request.urlopen(req) as r:
                return json.load(r)
        except urllib.error.HTTPError as e:
            msg = e.read().decode()[:400]

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…