pycarddav icon indicating copy to clipboard operation
pycarddav copied to clipboard

UnicodeDecodeError in model._pretty_base for PHOTO property

Open haphi opened this issue 12 years ago • 6 comments

when running "pc_query -a" on a contact with a jpeg PHOTO, python fails with:

Traceback (most recent call last):
  File "/usr/bin/pc_query", line 88, in <module>
    controllers.query(conf)
  File "/usr/lib/python2.7/site-packages/pycarddav/controllers.py", line 107, in query
    lines = vcard.pretty
  File "/usr/lib/python2.7/site-packages/pycarddav/model.py", line 236, in pretty
    return self._pretty_base(self.alt_keys())
  File "/usr/lib/python2.7/site-packages/pycarddav/model.py", line 251, in _pretty_base
    line = key + types + ': ' + value[0]
 UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

Possible solution might be to prevent "PHOTO" property from being pretty-printed or using a try/catch block to automatically filter any non-printable properties.

haphi avatar Mar 08 '13 19:03 haphi

Sorry for getting back to this so late. This really shouldn't happen, since all embedded images should be base64 encoded. I'm not really sure if just ignoring it (like in your pull request) is the best way to deal with this. Do you know which application created this vcard ? and do other applications display the image correctly?

geier avatar Mar 25 '13 12:03 geier

I only have two vcards with "PHOTO"-properties, in both cases binary encoded. One was created by an android phone an synced through an OwnCloud-server, the other one has some 'history', that I cannot really trace back anymore. I thought ignoring at that point in the code would be OK as there is no good way to pretty-print non-printable data. Of course, come to think of it, instead of dropping the field alltogether, a 'binary' hint would be better, as the user should expect "pc_query -a" to show all existing tags.

haphi avatar Mar 25 '13 12:03 haphi

so does owncloud display the image correctly?

I guess a hint or something else is probably better than dropping it altogether

geier avatar Mar 25 '13 12:03 geier

yes, ownclowd, the android address book and evolution all display the image correctly. so maybe something like this would be better:

                try:
                    line = key + types + ': ' + value[0]
                except UnicodeDecodeError:
                    line = key + types + ': <BINARY DATA>'
                collector.append(line)

haphi avatar Mar 25 '13 13:03 haphi

thanks for bringing this to my attention, it should be fixed in 07589c762582a75a977dae3cae3ce51f5c8e5c51 . I'll leave this issue open, since I still want to find out why this happens in the first place.

geier avatar Mar 27 '13 22:03 geier

If you want to be named in the contributors file, please give me a name, email address, etc

geier avatar Mar 27 '13 22:03 geier