如何使用PyGithub在存储库中创建文件? [英] How to create a file inside a repository using PyGithub?

查看:139
本文介绍了如何使用PyGithub在存储库中创建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如文档所示,在 github.Repository.Repository 对象上调用 create_file 应该创建一个文件,但是我我得到 github.GithubException.UnknownObjectException

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

我的代码如下所示:

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

我做错了什么?

推荐答案

看来您需要用斜杠 / 开始文件名。我已经尝试了下面的命令,它的工作原理如下:

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")}

这篇关于如何使用PyGithub在存储库中创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆