以下代码示例是文档中的修改版本:http: //python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html#file-uploads。
如果您收到带有单个键“upload_file”的 AttributeError。然后将 project.upload_file() 属性更新为 project.upload()。
感谢@JonathanPorter 对此的帮助。
project = gl.projects.get('vogon/bypass')
issue = project.issues.get(42)
try:
# note: use project.upload() not project.upload_file()
uploaded_file = project.upload("the_answer_to_life.txt",
filedata="data")
issue.notes.create({
"body": "See the [attached file]
({})".format(uploaded_file["url"])
})
except Exception as e:
self.log.debug(e[0])