让 Python Gitlab 文件上传示例工作的指南
Guidance on getting the Python Gitlab file upload sample to work
以下代码示例是文档中内容的修改版本:http://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html#file-uploads。
如果您收到带有单个键的 AttributeError 'upload_file'。然后将 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
.
的属性
通常这意味着它没有被显式导入(即 import gl.upload_file
),但在这种情况下 upload_file
根本不存在,upload
是正确的使用方法.
以下代码示例是文档中内容的修改版本:http://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html#file-uploads。
如果您收到带有单个键的 AttributeError 'upload_file'。然后将 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
.
通常这意味着它没有被显式导入(即 import gl.upload_file
),但在这种情况下 upload_file
根本不存在,upload
是正确的使用方法.