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])
您看到屬性錯誤,因爲'project'模塊沒有任何名爲'upload_file'的屬性。您必須通過顯式導入來定義屬性。 –
謝謝! @JonathanPorter看起來文檔可能有一些不一致之處。我已經更新了屬性project.upload()而不是project.upload_file(),它的工作。 –