2017-10-04 43 views
0

以下代碼示例是文檔中找到的修改版本: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(),它的工作。 –

回答

1

你看到一個屬性錯誤,因爲project模塊沒有名爲upload_file任何屬性。

通常這意味着它沒有明確導入(即import gl.upload_file),但在這種情況下,upload_file根本不存在,並且upload是正確的使用方法。