I have a Vcard string and I want to transform it to a Vobject : I did the following and I got the mentioned error , my question is what is this error and how can I transform a string to a vcard object?
my_str = "BEGIN:VCARD
VERSION:3.0
N;CHARSET=UTF-8:ContactName;;;;
TEL:0000000000
END:VCARD"
vcard = vobject.readOne(my_str)
stack trace:
error: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/vobject/base.py", line 1156, in readOne
allowQP))
File "/usr/local/lib/python2.7/dist-packages/vobject/base.py", line 1142, in readComponents
(stack.topName())), n)
vobject.base.ParseError: At line 1: Component VCARD was never closed
What is this error?
As posted, the supplied code will raise a SyntaxError: as @Frodon's comment says, you would need to use """ (or ''') to have the string span multiple lines like that.
For example, this code:
Causes the interpreter to report:
The reported error from vobject means that the string you're actually trying to parse has no "END:VCARD" line.
For example
but
How can I transform a string to a vcard object?
To your second question, for parsing a vCard, you're doing the right thing: use
vobject.readOne()
orvobject.readComponents()
. If your input data doesn't have the END:VCARD line truncated, it should parse correctly, returning you a vCard object.