Open yannc2021 opened 6 years ago
Can you please provide the object that caused this error?
I'm not the original poster but I was able to reproduce this error in vobject version 0.9.6.1 and python version 3.10.6 I believe this has something to do with encoding photos in base64. My minimal working example is
import vobject
card_text_ok = '''
BEGIN:VCARD
VERSION:2.1
FN:ok
PHOTO;type=JPEG:
END:VCARD
'''
card_text_bad = '''
BEGIN:VCARD
VERSION:2.1
FN:bad
PHOTO;ENCODING=BASE64;TYPE=JPEG:
END:VCARD
'''
if __name__ == '__main__':
card = vobject.readOne(card_text_ok)
print(card.serialize())
card = vobject.readOne(card_text_bad)
print(card.serialize())
Note that I specify the ENCODING
parameter in the photo property. I'm pretty sure this is valid vCard2.1
The stack trace is essentially the same except for a few different line numbers
Traceback (most recent call last):
File "/home/philip-stuckey/Projects/contact-fs/src/err.py", line 23, in <module>
print(card.serialize())
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/base.py", line 254, in serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/behavior.py", line 166, in serialize
out = base.defaultSerialize(transformed, buf, lineLength)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/base.py", line 1007, in defaultSerialize
child.serialize(outbuf, lineLength, validate=False)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/base.py", line 254, in serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/vcard.py", line 237, in serialize
VCardTextBehavior.serialize(obj, buf, lineLength, validate)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/behavior.py", line 166, in serialize
out = base.defaultSerialize(transformed, buf, lineLength)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/base.py", line 1015, in defaultSerialize
obj.behavior.encode(obj)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/vcard.py", line 161, in encode
line.value = backslashEscape(line.value)
File "/home/philip-stuckey/Projects/contact-fs/venv/lib/python3.10/site-packages/vobject/base.py", line 1219, in backslashEscape
s = s.replace("\\", "\\\\").replace(";", "\;").replace(",", "\,")
TypeError: a bytes-like object is required, not 'str'