我正在尝试从我的私人github存储库下载最新版本。我已经设置了令牌,我可以检索版本信息,但无法下载版本。
import requests
from requests.auth import HTTPBasicAuth
r = requests.get(
'https://MYTOKEN:@api.github.com/repos/andrewtquick/releasetest/releases/latest')
d = r.json()['assets'][0]["browser_download_url"]
with open('c:/temp/app.exe', 'wb') as f:
download = requests.get(d, headers={'Authorization': 'MYTOKEN'})
f.write(download.content)我一直收到404个回复..我已经尝试在头文件中使用我的令牌,还尝试在请求HTTPBasicAuth中使用我的登录凭据。似乎什么都不起作用..
当我检查url的accepted头时,我得到了以下内容:
{'Server': 'GitHub.com',
'Date': 'Thu,
09 Jul 2020 17:34:47 GMT',
'Content-Type': 'application/json; charset=utf-8',
'Transfer-Encoding': 'chunked',
'Status': '200 OK',
'X-RateLimit-Limit': '5000',
'X-RateLimit-Remaining': '4992',
'X-RateLimit-Reset': '1594318601',
'Cache-Control': 'private,
max-age=60,
s-maxage=60',
'Vary': 'Accept,
Authorization,
Cookie,
X-GitHub-OTP,
Accept-Encoding,
Accept,
X-Requested-With',
'ETag': 'W/"44f010aed319d40ab177528a8f41dc78"',
'X-OAuth-Scopes': 'read:packages,
repo',
'X-Accepted-OAuth-Scopes': 'repo',
'X-GitHub-Media-Type': 'github.v3; format=json',
'Access-Control-Expose-Headers': 'ETag,
Link,
Location,
Retry-After,
X-GitHub-OTP,
X-RateLimit-Limit,
X-RateLimit-Remaining,
X-RateLimit-Reset,
X-OAuth-Scopes,
X-Accepted-OAuth-Scopes,
X-Poll-Interval,
X-GitHub-Media-Type,
Deprecation,
Sunset',
'Access-Control-Allow-Origin': '*',
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload',
'X-Frame-Options': 'deny',
'X-Content-Type-Options': 'nosniff',
'X-XSS-Protection': '1; mode=block',
'Referrer-Policy': 'origin-when-cross-origin,
strict-origin-when-cross-origin',
'Content-Security-Policy': "default-src 'none'",
'Content-Encoding': 'gzip',
'X-GitHub-Request-Id': '4E08:54CB:3CB13C:671519:5F075537'}我可以看到Authorization头和Accept头。我试过使用github的建议,将头部设置为'application/octet-stream',但这也不起作用。
发布于 2020-07-12 09:07:44
通常使用MYTOKEN作为密码:
r = requests.get(
'https://<username>:MYTOKEN@api.github.com/repos/andrewtquick/releasetest/releases/latest')与this example中的一样
url = urljoin(GITHUB_API, 'authorizations')
payload = {}
if note:
payload['note'] = note
res = requests.post(
url,
auth = (username, password),
data = json.dumps(payload),
)除非您将GitHub帐户密码替换为PAT (Personal Access Token)。
https://stackoverflow.com/questions/62820701
复制相似问题