jowave/vcard2to3

ValueError: string argument should contain only ASCII characters

wurzelbutz opened this issue · 5 comments

Hi

I just tried to convert the vcf created with MyPhoneExplorer to version 3.
Unfortunately it does not work:

python3 vcard2to3.py vcard2.vcf Traceback (most recent call last): File "/home/pi/kontakte_tmp/vcard2to3/vcard2to3.py", line 250, in <module> main(sys.argv[1:]) File "/home/pi/kontakte_tmp/vcard2to3/vcard2to3.py", line 237, in main line = decoder.decode(line) File "/home/pi/kontakte_tmp/vcard2to3/vcard2to3.py", line 115, in decode decoded_line = quopri.decodestring(line).decode(self.encoding) File "/usr/lib/python3.9/quopri.py", line 162, in decodestring return a2b_qp(s, header=header) ValueError: string argument should contain only ASCII characters

Any idea how to solve this?
Thanks!
BR,
Hugo

The error message says that it cannot decode some value encoded as QUOTED-PRINTABLE. Probably your file contains some lines similar to (taken from examples.vcf)

FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=D0=B3=D0=BE=D1=80=20=D0=97=D0=B0=D0=BE=D1=80=D1=81=D0=81=D0=
=BA=
=D1=96=
 xyz =
=D1=96

But these cannot be decoded, because there are invalid characters.
Either your file contains invalid values or my regex matching the quoted printable value does not cover your use case.
If you can provide an example of a vCard, I can look into it. Please remove any private information from your example.

@wurzelbutz Could you solve your issue?

yes and no. finally I used KAddressbook to convert the vcf.
I extracted all the quoted printables from my vcf and removed personal data.
this is the file (which still fails to convert).
vcard2qp.txt

Thanks for the feedback and the sample file.
Your file contains öüß in the quoted printable data (e.g. line 88). These are not valid characters, since in quoted printable representation only 7-bit ascii characters are allowed and all others are encoded with = followed by two hex digits.
Additionally in line 188 is an invalid hex sequence =C3=9=C3=9FF, guessing this should be =C3=9F which is ß in utf-8.

I will add an error message to the script to help identifying the culprit line(s).

After correcting the errors the file can be converted successfully.
vcard2qp.corrected.txt

(Note: There is one more possible source of error, since my script ignores the CHARSET=UTF-8 in quoted printable lines and instead uses always the input encoding, which can be given as parameter. For your file this is not a problem though.)

thank you!