从私人仓库下载带有令牌的最新版本文件

问题描述 投票:0回答:1

我想使用 python 从我的私人存储库下载文件。

我该怎么办?

我尝试过类似的方法,但不起作用。 我还允许令牌中的所有内容进行测试,我再次遇到错误。

import requests

headers = {'Authorization': 'token ' + 'ghp_xxxxxxxxxxxxxxx'}

def download_and_apply_update(self, loading_window):
        download_url = "https://github.com/HamzaYslmn/example/releases/latest/download/example.exe"
        new_executable_path = "DetaBaseFatura_New.exe"
    
        response = requests.get(download_url, stream=True , headers=headers)
        total_size = int(response.headers.get("content-length", 0))
        chunk_size = 8192  # You can adjust this value as needed
    
        with open(new_executable_path, "wb") as new_executable_file:
            downloaded_size = 0
            for data in response.iter_content(chunk_size=chunk_size):
                new_executable_file.write(data)
                downloaded_size += len(data)
                progress_percentage = (downloaded_size / total_size) * 100
                loading_window[1]["text"] = f"Progress: {progress_percentage:.2f}%"
                loading_window[2]["value"] = progress_percentage
                loading_window[0].update()
    

例如,这样我就可以访问标签。但下载是完全不同的事情。

def get_latest_version_from_github(self):
        latest_tag_url = "https://api.github.com/repos/HamzaYslmn/example/releases/latest"
        response = requests.get(latest_tag_url, headers=headers)
        response_data = response.json()
        print(response_data)
        latest_tag = response_data['tag_name']
        
        return latest_tag
python github pip github-api pygithub
1个回答
0
投票
latest_tag_url = "https://api.github.com/repos/HamzaYslmn/{REPO}/releases/latest"
        headers = {
            "Accept": "application/vnd.github+json",
            "Authorization": "Bearer ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "X-GitHub-Api-Version": "2022-11-28"
        }
        response = requests.get(latest_tag_url, headers=headers)

我解决了

© www.soinside.com 2019 - 2024. All rights reserved.