使Python Gitlab文件上传示例正常工作的指导

问题描述:

以下代码示例是文档中找到的修改版本:http://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html#file-uploads使Python Gitlab文件上传示例正常工作的指导

如果您收到带有一个键'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]) 
+0

您看到属性错误,因为'project'模块没有任何名为'upload_file'的属性。您必须通过显式导入来定义属性。 –

+0

谢谢! @JonathanPorter看起来文档可能有一些不一致之处。我已经更新了属性project.upload()而不是project.upload_file(),它的工作。 –

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

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