0

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])
  • You're seeing an attribute error because the `project` module doesn't have any attribute named `upload_file`. You'll have to define the attribute by importing it explicitly. – Jonathan Porter Oct 04 '17 at 21:11
  • Thanks! @JonathanPorter It looks like the documentation may have some inconsistencies. I've updated the attribute to project.upload() instead of project.upload_file() and it worked. – Mohammed Shamma Oct 04 '17 at 21:39

1 Answers1

1

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.

Jonathan Porter
  • 1,365
  • 7
  • 34
  • 62