Files uploaded via the web interface create a Token #214038
Replies: 3 comments
|
That Two ways to keep your Python code stable:
Keep the PAT out of the script (e.g. read it from an environment variable). |
|
Thank you for the reply!
…On Wed, Nov 25, 2026, 12:14 PM Leonardo Carvalho ***@***.***> wrote:
That ?token=... suffix is what the "Raw" button adds when the file lives
in a *private* repository. The token is short-lived, so the URL changes
and you cannot hardcode it. If the repo was recently switched from public
to private, that would explain why it started suddenly (I have not verified
that for your repo).
Two ways to keep your Python code stable:
1. Skip the tokenized link and authenticate with a personal access
token (fine-grained, read-only on "Contents" for that repo). Either request
https://raw.githubusercontent.com/<owner>/<repo>/<branch>/<path>.csv
with the header Authorization: token <PAT>, or use the REST contents
API (GET /repos/<owner>/<repo>/contents/<path>) with Accept:
application/vnd.github.raw. The URL stays the same after every update.
2. If the data is not sensitive, make the repo public and the plain
raw URL works without any token.
Keep the PAT out of the script (e.g. read it from an environment variable).
—
Reply to this email directly, view it on GitHub
<#214038?email_source=notifications&email_token=AKRJJHDXTMQVG2Y7ZGTATBD524HPBA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCOJYHE3DANRQUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVRTG633UMVZF6Y3MNFRWW#discussioncomment-19896060>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKRJJHGUYJIVJZQNZOYIMMT524HPBAVCNFSNUABIKJSXA33TNF2G64TZHMZTAMJVG4ZTGNBUHNCGS43DOVZXG2LPNY5TCMJTHE4TANRQUF3AE>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AKRJJHDU4FKPECD5LKB6AAD524HPBA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCOJYHE3DANRQUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVJTG633UMVZF62LPOM>
and Android
<https://github.com/notifications/mobile/android/AKRJJHAH6US23CHWBS6PA73524HPBA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCOJYHE3DANRQUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVZTG633UMVZF6YLOMRZG62LE>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
The Three ways to fix it, in order of preference: 1. Use the authenticated API instead of the raw URL (best for scripts): import requests, os
url = "https://api.github.com/repos/OWNER/REPO/contents/data.csv"
r = requests.get(url, headers={
"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}",
"Accept": "application/vnd.github.raw",
})
r.raise_for_status()
text = r.textThis needs a token with 2. Use a fine-grained PAT in the raw URL — not recommended, but it works: The token is long-lived, but you're putting a credential in a URL, so don't commit it or log it. 3. Make the file public if it doesn't need to be private. Then the plain Why not just re-fetch the token each time? You could scrape the redirect from the One more thing worth checking: if the repo is private but you're the owner, |
Uh oh!
There was an error while loading. Please reload this page.
💬 Feature/Topic Area
Issues
Body
I am uploading a csv file via the web interface and accessing the data with Python. I was using the raw datafile and things were working perfectly. I was able to replace the file with updates several times and still able to access the file. Now when I update, it creates a token value on the file that changes every time, forcing me to change my code. Why would it suddenly create this token? Ami I missing an easier way to update the file an keep the connection intact?
All reactions