简体   繁体   English

从带有 python 的私有 github 仓库下载资产

[英]Download asset from private github repo with python

I'm trying to download the latest release from my private github repo.我正在尝试从我的私人 github 存储库下载最新版本。 I've setup a token, I can retrieve the release information, but I can't download the release.我已经设置了一个令牌,我可以检索发布信息,但我无法下载发布。

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)

I keep getting 404 responses.. I've tried to use my token in the headers and also tried to use my login credentials with requests HTTPBasicAuth.. Nothing seems to work..我不断收到 404 响应。我尝试在标头中使用我的令牌,还尝试将我的登录凭据与请求 HTTPBasicAuth 一起使用。似乎没有任何效果。

When I check the accepted headers for the url, I get the following:当我检查 url 的接受标头时,我得到以下信息:

{'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'}

I can see the Authorization header and the Accept header.我可以看到授权 header 和接受 header。 I've tried using github's recommendation on setting the header to 'application/octet-stream', but this doesn't work either.我尝试使用 github 的建议将 header 设置为“application/octet-stream”,但这也不起作用。

Usually, MYTOKEN is used as password:通常,MYTOKEN 用作密码:

 r = requests.get(
'https://<username>:MYTOKEN@api.github.com/repos/andrewtquick/releasetest/releases/latest')

As in this example :本例所示

url = urljoin(GITHUB_API, 'authorizations')
payload = {}
if note:
    payload['note'] = note
res = requests.post(
    url,
    auth = (username, password),
    data = json.dumps(payload),
    )

Except you would replace the GitHub account password by a PAT (Personal Access Token) .除非您将 GitHub 帐户密码替换为PAT(个人访问令牌)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 python 中的私有存储库下载 GitHub 发布资产? - How to download a GitHub release asset from a private repository in python? 在 python 中验证 Github 私有仓库 - Autheticate Github private repo in python 如何使用ssh为bitbucket / github从私人仓库下载文件? - How can I download files from a private repo with ssh for bitbucket/github? 私有Github python repo无法安装 - Private Github python repo cannot be installed 从 github repo 下载并从 repo 中导入 .py 文件以供使用 - Download from github repo and import .py file from the repo for usage 如何使用 ZA7F5F35426B927411FC9231B563 在 Github 上下载充满 CSV 文件的 Github 存储库? - How Download Github Repo Filled with CSV Files on Github using Python? 我如何使用jenkins从私人github存储库安装python软件包? - How do I install python package from private github repo using jenkins? Install a python package using pip from private GitHub repo when building Docker image? - Install a python package using pip from private GitHub repo when building Docker image? 在 python requirements.txt 中带有私有 github repo 的 DockerFile - DockerFile with private github repo in python requirements.txt Python 安装私有 github 回购给出“退出状态 128”错误? - Python installing private github repo giving "exit status 128" error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM