Как сохранить u-строки в Exif с piexif? - PullRequest
0 голосов
/ 10 октября 2018

Я получаю следующее:

import piexif
dict = {'Exif':{piexif.ExifIFD.UserComment: u"Hello World"}}
piexif.dump(dict)
Traceback (most recent call last):
  File "/opt/anaconda3/envs/py35/lib/python3.5/site-packages/piexif/_dump.py", line 267, in _value_to_bytes
    four_bytes_over = b"" + raw_value
TypeError: can't concat str to bytes
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/anaconda3/envs/py35/lib/python3.5/site-packages/piexif/_dump.py", line 337, in _dict_to_bytes
    offset)
  File "/opt/anaconda3/envs/py35/lib/python3.5/site-packages/piexif/_dump.py", line 269, in _value_to_bytes
    raise ValueError("Got invalid type to convert.")
ValueError: Got invalid type to convert.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/anaconda3/envs/py35/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-12-c4033cf70779>", line 1, in <module>
    piexif.dump(dict)
  File "/opt/anaconda3/envs/py35/lib/python3.5/site-packages/piexif/_dump.py", line 68, in dump
    exif_set = _dict_to_bytes(exif_ifd, "Exif", zeroth_length)
  File "/opt/anaconda3/envs/py35/lib/python3.5/site-packages/piexif/_dump.py", line 341, in _dict_to_bytes
    '{0} in {1} IFD. Got as {2}.'.format(key, ifd, type(ifd_dict[key]))
ValueError: "dump" got wrong type of exif value.
37510 in Exif IFD. Got as <class 'str'>.

Хотя в примерах документации используются u-строки.

Почему и как правильно с этим обращаться?

b'Hello World' работает и работает "Hello World".encode('utf-8')


Если я сохраняю b-струны, я получаю следующее во внешнем инструменте:

enter image description here

...