0

以下代码示例是文档中的修改版本: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])
4

1 回答 1

1

您看到一个属性错误,因为该project模块没有任何名为upload_file.

通常这意味着它没有显式导入(即import gl.upload_file),但在这种情况下upload_file根本不存在并且upload是正确的使用方法。

于 2017-10-05T12:59:32.667 回答