INNER CODE UNIT · Python

github_json

oneclickvirt/ecs · agent/server.py:95

def github_json(path):
    headers = {"Accept": "application/vnd.github+json", "User-Agent": "oneclickvirt-mcp/" + VERSION}
    token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
    if token:
        headers["Authorization"] = "Bearer " + token
    class SafeRedirect(urllib.request.HTTPRedirectHandler):
        def redirect_request(self, req, fp, code, msg, response_headers, newurl):
            redirected = super().redirect_request(req, fp, code, msg, response_headers, newurl)
            if redirected is not None and urllib.parse.urlsplit(newurl).netloc != "api.github.com":
                redirected.remove_header("Authorization")
            return redirected
    req = urllib.request.Request("https://api.github.com" + path, headers=headers)
    try:
        with urllib.request.build_opener(SafeRedirect()).open(req, timeout=25) as response:
            data = response.read(8 * LIMIT + 1)
    except urllib.error.HTTPError as exc:
        raise ValueError("GitHub API returned %s; no release or asset is assumed" % exc.code) from None
    if len(data) > 8 * LIMIT:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…