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])
2
  • 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. Commented Oct 4, 2017 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. Commented Oct 4, 2017 at 21:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.