CoolFace
Apppublic

LZ-SG/embedded-dev-tutorials

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
check_pat.py25 linesDownload Raw Back to root
1#!/usr/bin/env python32import urllib.request, json3TOKEN = "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"4 5# Test PAT validity6r = urllib.request.Request("https://api.github.com/user",7    headers={"Authorization": f"token {TOKEN}", "Accept": "application/vnd.github.v3+json", "User-Agent": "test"})8try:9    with urllib.request.urlopen(r, timeout=15) as resp:10        data = json.loads(resp.read())11        print(f"OK user={data.get('login')} scopes={resp.headers.get('X-OAuth-Scopes')}")12except Exception as e:13    print(f"USER FAIL: {e}")14 15# Try repo access16for repo_name in ["SG06231219-boop/embedded-dev-tutorials", "sg06231219-boop/embedded-dev-tutorials"]:17    r2 = urllib.request.Request(f"https://api.github.com/repos/{repo_name}",18        headers={"Authorization": f"token {TOKEN}", "Accept": "application/vnd.github.v3+json", "User-Agent": "test"})19    try:20        with urllib.request.urlopen(r2, timeout=15) as resp:21            d = json.loads(resp.read())22            print(f"Repo {repo_name}: full_name={d.get('full_name')} default_branch={d.get('default_branch')}")23    except Exception as e:24        print(f"Repo {repo_name}: {e}")25