我得到以下信息:
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'>.
尽管使用了in documentation examples u字符串。
为什么以及如何正确处理它?</ p>
b'Hello World'
也有效,"Hello World".encode('utf-8')
如果我保存b字符串,则可以在外部工具中获得以下信息: