You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "create_submission_point_for_group.py", line 261, in
project.files.create(blob)
File "/usr/local/lib/python2.7/dist-packages/gitlab/cli.py", line 42, in wrapped_f
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/gitlab/exceptions.py", line 247, in wrapped_f
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/gitlab/v4/objects.py", line 1806, in create
server_data = self.gitlab.http_post(path, post_data=new_data, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/gitlab/init.py", line 792, in http_post
post_data=post_data, files=files, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/gitlab/init.py", line 678, in http_request
prepped = self.session.prepare_request(req)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 394, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 298, in prepare
self.prepare_body(data, files, json)
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 424, in prepare_body
body = complexjson.dumps(json)
File "/usr/lib/python2.7/dist-packages/simplejson/init.py", line 380, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 291, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 373, in iterencode
return _iterencode(o, 0)
This makes it seem like the python api is ignoring the encoding option. I've ensured the encoding is set to base64 in the 'blob' that I've passed to project.files.create(). Other ordinary files without the encoding commit perfectly fine.
The text was updated successfully, but these errors were encountered:
After a long look around I found that you actually have to use the package base64 to encode the file, something like below
encoding = "text"
content = open(f,"r").read()
if IsBinaryFile(f): # Uses pip package binaryornot to determine if it's a binary file
encoding = "base64"
content = base64.b64encode(content)
# Add to the data blob of all files being added
data["actions"].append({
"action": "create",
"file_path": filename,
"encoding": encoding,
"content": content
})
I might suggest that something should be added to commits documentation describing how to handle the encoding, as it's not particularly clear for someone that's new to how the API works. Here's the page I mean:
When I'm trying to commit a binary file into a repository and setting the encoding to "base64" (as specified in https://docs.gitlab.com/ce/api/repository_files.html#create-new-file-in-repository), I'm getting the following error:
This makes it seem like the python api is ignoring the encoding option. I've ensured the encoding is set to base64 in the 'blob' that I've passed to project.files.create(). Other ordinary files without the encoding commit perfectly fine.
The text was updated successfully, but these errors were encountered: