Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespace_api > create_file doesn't honor content-type parameter #19

Open
iulianmanole opened this issue Jan 11, 2020 · 0 comments
Open
Labels
Bug_SDK Bugs related to SDK and surrounding scripts

Comments

@iulianmanole
Copy link

Hi,

I am trying to use the namespaceApi > create_file, using the example provided in documentation, to create a pdf file.
The operation fails with TypeError: Object of type 'bytes' is not JSON serializable (stack trace below).
From my investigations it seems that the Content-Type supplied as parameter to create_file gets overridden in create_file_with_http_info(file_path, x_isi_ifs_target_type, file_contents, **kwargs) to application/json.

Am I missing something ?

Expected result:
The file should be created with the provided content.

** Environment**

python 3.6 
rhel 7.x 
isilon 8.0.0.6 

sample code

import isi_sdk_8_0
import base64

# configure client
configuration = isi_sdk_8_0.Configuration()
configuration.host = 'https://isilon:8080'
configuration.username = 'root'
configuration.password = 'bla'
configuration.verify_ssl = False

## create api instance
api_instance = isi_sdk_8_0.NamespaceApi(isi_sdk_8_0.ApiClient(configuration))

## upload /tmp/sample.txt

file_path = 'esign-ap/sample.txt' # str | File path relative to /.
x_isi_ifs_target_type = 'object' # str | Specifies the resource type. (default to object)
x_isi_ifs_access_control = '0600' # str | Specifies a pre-defined ACL value or POSIX mode with a string in octal string format. (optional) (default to 0600)
content_encoding = None # str | Specifies the content encoding that was applied to the object content, so that decoding can be applied when retrieving the content. (optional)
content_type = 'binary/octet-stream' # str | Specifies a standard MIME-type description of the content format. (optional) (default to binary/octet-stream)
overwrite = True # bool | Deletes and replaces the existing user attributes and ACLs of the directory with user-specified attributes and ACLS from the header, when set to true. (optional)

file_contents = 'file_contents_example' # str | The contents of the file object.
local_file_path = '/tmp/sample.pdf'

with open(local_file_path, 'rb') as f:
    file_contents = f.read()

api_response = api_instance.create_file(file_path, x_isi_ifs_target_type, file_contents, x_isi_ifs_access_control=x_isi_ifs_access_control, overwrite=overwrite)

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/app-root/lib/python3.6/site-packages/isi_sdk_8_0/api/namespace_api.py", line 529, in create_file
    (data) = self.create_file_with_http_info(file_path, x_isi_ifs_target_type, file_contents, **kwargs)  # noqa: E501
  File "/opt/app-root/lib/python3.6/site-packages/isi_sdk_8_0/api/namespace_api.py", line 633, in create_file_with_http_info
    collection_formats=collection_formats)
  File "/opt/app-root/lib/python3.6/site-packages/isi_sdk_8_0/api_client.py", line 346, in call_api
    _preload_content, _request_timeout)
  File "/opt/app-root/lib/python3.6/site-packages/isi_sdk_8_0/api_client.py", line 177, in __call_api
    _request_timeout=_request_timeout)
  File "/opt/app-root/lib/python3.6/site-packages/isi_sdk_8_0/api_client.py", line 397, in request
    body=body)
  File "/opt/app-root/lib/python3.6/site-packages/isi_sdk_8_0/rest.py", line 369, in PUT
    body=body)
  File "/opt/app-root/lib/python3.6/site-packages/isi_sdk_8_0/rest.py", line 164, in request
    request_body = json.dumps(body)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable
@vboddui vboddui added the Bug_SDK Bugs related to SDK and surrounding scripts label May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug_SDK Bugs related to SDK and surrounding scripts
Projects
None yet
Development

No branches or pull requests

2 participants