python-openxml / python-docx

Create and modify Word documents with Python
MIT License
4.64k stars 1.13k forks source link

Failed to read image file while add_picture #350

Open xanarry opened 7 years ago

xanarry commented 7 years ago

when i add a picture to doc file, I get this error

File "/usr/local/lib/python3.5/dist-packages/python_docx-0.8.6-py3.5.egg/docx/image/helpers.py", line 71, in read_str
    unicode_str = chars.decode('UTF-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 12: invalid continuation byte

so, I edit helpers.py, and change unicode_str = chars.decode('UTF-8') to unicode_str = chars.decode('UTF-8', errors="ignore") it works, does it any matter, if use the later code

jonasao commented 6 years ago

@xanarry by using unicode_str = chars.decode('UTF-8', errors="ignore") you will not be notified if any errors occurs. If you are fine with that, it does not matter. When said; you should not have to add the errors="ignore" flag, but instead attempt to find out why reading the specific picture-/image file fails.