Skip to content
This repository was archived by the owner on Dec 27, 2018. It is now read-only.
This repository was archived by the owner on Dec 27, 2018. It is now read-only.

How to include the comments and minorEdit fields when uploading attachments #26

Description

@efrose

Hi,

I'm using update_attachment to upload a new version of an image attachment.
I can upload the file, but when I include the comments or minorEdit in the attachment metadata, the requests library treats it like a file to be uploaded.

        attachment_content = {
            'comment': comment,
            'minorEdit': False,
            'file': (filepath, open(filepath, mode='rb'))
        }
        result = api.update_attachment(pageid, attachment_id, attachment_content)

Error thread:

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PythonConfluenceAPI/api.py", line 1048, in update_attachment
callback=callback)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PythonConfluenceAPI/api.py", line 140, in _service_post_request
return self._service_request("POST", *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PythonConfluenceAPI/api.py", line 114, in _service_request
response = self.session.request(request_type, uri, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 474, in request
prep = self.prepare_request(req)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/sessions.py", line 407, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/models.py", line 305, in prepare
self.prepare_body(data, files, json)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/models.py", line 483, in prepare_body
(body, content_type) = self._encode_files(files, data)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/models.py", line 158, in _encode_files
fdata = fp.read()

Problem is that the attachment dict is passed straight to the requests library, and all items are treated as files. It tries to upload "minorEdit" and fails because it's a bool.

Is there a way to separate the attachment metadata from the attachment data itself in this call?

Thanks,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions