我正在尝试使用以下代码将.csv文件上载到GitHub:
### THIS PART WOKRS ###
g = Github("My_Access_Key")
repo = g.get_user().get_repo('tradr')
all_files = []
contents = repo.get_contents("")
while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(repo.get_contents(file_content.path))
else:
file = file_content
all_files.append(str(file).replace('ContentFile(path="','').replace('")',''))
with open('./Data/PriceGrabber/PriceData.csv', 'r') as file:
content = file.read()
# Upload to github
git_prefix = 'tradr/'
git_file = git_prefix + 'PriceData.csv'
### THIS PART WORKS ###
### GET AN ERROR HERE BELOW ###
if git_file in all_files:
contents = repo.get_contents(git_file)
repo.update_file(contents.path, "committing files", content, contents.sha, branch="master")
print(git_file + ' UPDATED')
else:
repo.create_file(git_file, "committing files", content, branch="master")
print(git_file + ' CREATED')
这是我得到的错误:
GithubException: 404 {"message": "Branch master not found", "documentation_url": "https://docs.github.com/rest/reference/repos#create-or-update-file-contents"}
我可以使用任何可能更好的方法。搜索似乎表明这可能是一个身份验证问题[1]
我也有同样的问题。 在我通过branch='main'更改了branch='master'之后,它工作了
那是因为:https://www.zdnet.com/article/github-to-replace-master-with-main-starting-next-month/
干杯
相关问题 更多 >
编程相关推荐