I am trying to commit a PDF using python-gitlab library. I am using the document found in https://python-gitlab.readthedocs.io/en/stable/gl_objects/commits.html.
I encode the pdf using
{
# Binary files need to be base64 encoded
'action': 'create',
'file_path': 'file.pdf',
'content': base64.b64encode(open('file.pdf').read()),
'encoding': 'base64',
}
But I get an error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 171: invalid start byte.
I then try to do
{
# Binary files need to be base64 encoded
'action': 'create',
'file_path': 'file.pdf',
'content': base64.b64encode(open('file.pdf', 'rb').read()),
'encoding': 'base64',
}
Basically changing it to bytes, but then I will get an error
TypeError: Object of type bytes is not JSON serializable
When trying to commit the data using the command
commit = project.commits.create(data)
Which makes sense, since the data is now in bytes and cannot be serialized by json. How can I work around/or how should this be implemented?