How to create a file inside a repository using PyGithub?

两盒软妹~` 提交于 2019-12-06 10:26:16

问题


As the documentation suggests, calling create_file on a github.Repository.Repository object should create a file but I am getting github.GithubException.UnknownObjectException.

My code is like this:

`repo.create_file('filename', 'commitmessage', 'content')`

What am I doing wrong?


回答1:


It seems that you need to start the filename with a slash /. I've tried the following command, and it worked:

In [12]: repo.create_file('/filename', 'commitmessage', 'content')
Out[12]:
{'commit': Commit(sha="201e0e5b91f7ec431d5b06cc47affff202e3de04"),
 'content': ContentFile(path="filename")}


来源:https://stackoverflow.com/questions/40610082/how-to-create-a-file-inside-a-repository-using-pygithub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!