Mohammed Shamma
Mohammed Shamma

Reputation: 35

Guidance on getting the Python Gitlab file upload sample to work

The following code sample is a modified version of what's found in the documentation at: http://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html#file-uploads.

If you receive an AttributeError with a single key 'upload_file'. Then update the project.upload_file() attribute to project.upload().

Thanks to @JonathanPorter for help with this.

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])

Upvotes: 0

Views: 520

Answers (1)

Jonathan Porter
Jonathan Porter

Reputation: 1556

You're seeing an attribute error because the project module doesn't have any attribute named upload_file.

Normally this means that it wasn't imported it explicitly (i.e. import gl.upload_file) but in this case upload_file simply didn't exist and upload was the correct method to use.

Upvotes: 1

Related Questions