我有以下代码:
import github
token = "my gitHub token"
g = github.Github(token)
new_repo = g.get_user().create_repo("NewMyTestRepo")
print("New repo: ", new_repo)
new_repo.create_file("new_file.txt", "init commit", "file_content ------ ")
我已经运行了这段代码,这是结果:
New repo: Repository(full_name="myname/NewMyTestRepo")
Traceback (most recent call last):
...
File "/home/serega/PycharmProjects/GitProj/myvenv/lib/python3.5/site-packages/github/Requester.py", line 180, in __check
raise self.__createException(status, responseHeaders, output)
github.GithubException.UnknownObjectException: 404 {'message': 'Not Found', 'documentation_url': 'https://developer.github.com/v3'}
我认为我的令牌范围可能存在问题,它具有回购范围。不过,我已经设法创建了一个存储库,因此看来,应该允许它在其中包含新文件的该存储库中进行提交。
关于作用域,我看到了该链接:https : //developer.github.com/v3/oauth/#scopes
它指出:
repo
授予对公共,私有存储库和组织的代码,提交状态,存储库邀请,协作者和部署状态的读/写访问权限。
如果有人可以澄清所需令牌的范围以及可能是什么问题,我将不胜感激。
repo
作用域足以在存储库中创建文件。从这个问题看来,问题在于您的文件必须以斜杠开头:
new_repo.create_file("new_file.txt", "init commit", "file_content ------ ")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句