how to check with vobject either string is valid vcard or not?
Is there some extra method or generall approach with try and catch?
For now I do it as follows:
try:
vobj = vobject.readOne(vcard_readable)
except Exception as e:
error_message = {
"valid": False,
"reason": "Invalid vCard\n{0}".format(e)}
How to deal with unicode with VOBJECT?
Your current code works fine, but generally you don't want to catch
Exception
because this will mask other errors in your code. For example, if I take your code snippet and put it in a file and then run it...I get no error messages, even though I have not imported thevobject
module. This is because that code is actually raising aNameError
:but because you're catching all exceptions, you're hiding it. A better technique is to catch only the specific exceptions you expect to receive from the
vobject
module, and let others percolate up normally.For
vobject
, all of the exceptions it raises are going to be subclasses ofvobject.base.VObjectError
, so the following code would suffice: