INNER CODE UNIT · Python
_request
dotnet/sdk · .github/scripts/check_vendored_files.py:159
def _request(url: str, accept: str = "application/vnd.github+json") -> tuple[int, bytes, dict[str, str]]:
token = os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
req = urllib.request.Request(url)
req.add_header("Accept", accept)
req.add_header("X-GitHub-Api-Version", "2022-11-28")
req.add_header("User-Agent", "dotnet-sdk-vendored-sync")
if token:
req.add_header("Authorization", f"Bearer {token}")
try:
with urllib.request.urlopen(req, timeout=30) as resp:
return resp.status, resp.read(), dict(resp.headers)
except urllib.error.HTTPError as e:
return e.code, e.read(), dict(e.headers or {})
def api_json(path: str) -> tuple[int, Any]:
url = f"{API_BASE}{path}"
status, body, _ = _request(url)