cloudinary / cloudinary-cli

A command line interface for Cloudinary's APIs
https://cloudinary.com/documentation/cloudinary_cli
MIT License
17 stars 10 forks source link

Upload fails with `Object of type CloudinaryImage is not JSON serializable` #42

Closed pinguinson closed 3 years ago

pinguinson commented 3 years ago

Bug report for Cloudinary CLI

Before proceeding, please update to the latest version and test if the issue persists

Describe the bug in a sentence or two.

Upload fails with Object of type CloudinaryImage is not JSON serializable, even though other methods (search, for example) work fine.

Issue Type (Can be multiple)

Steps to reproduce

-

Error screenshots or Stack Trace (if applicable)

~ cld -v DEBUG -C demo uploader upload_image ~/img/sample.jpg folder="demo"
Command execution failed, error: Object of type CloudinaryImage is not JSON serializable
Traceback (most recent call last):
  File "/home/gsk/.local/lib/python3.9/site-packages/cloudinary_cli/cli.py", line 58, in main
    exit_status = cli()
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/gsk/.local/lib/python3.9/site-packages/cloudinary_cli/core/uploader.py", line 30, in uploader
    return handle_api_command(params, optional_parameter, optional_parameter_parsed, ls, save, doc,
  File "/home/gsk/.local/lib/python3.9/site-packages/cloudinary_cli/utils/api_utils.py", line 172, in handle_api_command
    print_json(res)
  File "/home/gsk/.local/lib/python3.9/site-packages/cloudinary_cli/utils/json_utils.py", line 28, in print_json
    res_str = json.dumps(res, indent=2)
  File "/usr/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.9/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/usr/lib/python3.9/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type CloudinaryImage is not JSON serializable
error: Command execution failed, error: Object of type CloudinaryImage is not JSON serializable

Operating System

Environment and Frameworks (fill in the version numbers)

Repository

-

const-cloudinary commented 3 years ago

@pinguinson , thank you for reporting the issue!

upload_image is an internal function that was accidentally exported to the CLI, please use upload command instead, as follows: cld -v DEBUG -C demo uploader upload ~/img/sample.jpg folder="demo"

We will remove upload_image function in the future to avoid confusion.

pinguinson commented 3 years ago

@const-cloudinary uploader upload works like a charm, thanks!