cloudinary / pycloudinary

Python package for cloudinary
https://cloudinary.com/documentation/django_integration
Other
254 stars 138 forks source link

public_id UnicodeEncodeError #45

Closed oppianmatt closed 7 years ago

oppianmatt commented 9 years ago

We are in the process of converting our images from upload to private and they way we were told was to use the api to 'upload' each one as you can't change type. Problem is some of our images have unicode in the public_id yet the uploaded can't handle it. Here is an example:

We get the following resource in a list of resources from the api:

{u'secure_url': u'https://res.cloudinary.com/pitchup-com/image/upload/v1415177888/Camping_Man%C3%A9_Guernehu%C3%A9_txftuc.jpg', u'public_id': u'Camping_Man\xe9_Guernehu\xe9_txftuc', u'format': u'jpg', u'url': u'http://res.cloudinary.com/pitchup-com/image/upload/v1415177888/Camping_Man%C3%A9_Guernehu%C3%A9_txftuc.jpg', u'backup': True, u'created_at': u'2014-11-05T08:58:08Z', u'bytes': 18311, u'height': 131, u'width': 272, u'version': 1415177888, u'type': u'upload', u'resource_type': u'image'}

We call 'upload' like so:

                meta = upload(
                    resource['url'],
                    public_id=resource['public_id'],
                    eager=eager,
                    eager_async=True,
                    tags=tags,
                    type=settings.CLOUDINARY_TYPE,
                    image_metadata=True,
                )

and then we get the following stack trace:

  File "/usr/local/lib/python2.7/dist-packages/cloudinary/uploader.py", line 16, in upload
    return call_api("upload", params, file = file, **options)
  File "/usr/local/lib/python2.7/dist-packages/cloudinary/uploader.py", line 158, in call_api
    params = utils.sign_request(params, options)
  File "/usr/local/lib/python2.7/dist-packages/cloudinary/utils.py", line 114, in sign_request
    params["signature"] = api_sign_request(params, api_secret)
  File "/usr/local/lib/python2.7/dist-packages/cloudinary/utils.py", line 120, in api_sign_request
    to_sign = "&".join(sorted([(k+"="+(",".join(v) if isinstance(v, list) else str(v))) for k, v in params_to_sign.items() if v]))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 11: ordinal not in range(128)
iamwithnail commented 7 years ago

Was there any solution on this in the end? I have a similar issue on what I'm getting back from the call_api routine on images (without Unicode in the titles) for regular upload - it's working from commandline, but not from a form, which makes me wonder about what's going in/how it's being handled.

MaorGariv commented 7 years ago

Truly sorry for the late response. In case it's still relevant -

We have just recently deployed a new capability, which allows you to change the resource type using the rename API. A new parameter was added (to_type) for this purpose. This is currently only supported via a direct API call, Java and Node.js SDKs (we are working on supporting it via our other SDKs in the near future). Here is an example call, which demonstrates changing an image with public id 'my_public_id' to type private :

curl https://api.cloudinary.com/v1_1/cloud_name/image/rename -X POST --data 'from_public_id=my_public_id&to_public_id=my_public_id&to_type=private&timestamp=1473950489&api_key=123456&signature=d0f251a9e26e89a801abd4b62e6496d7c7164417'

idobarnoam commented 7 years ago

Closing this thread as there was no response for over two months.