I am new to python.I am trying to parse VCARD 2.1
file using vobject 0.9.2
python package.
I am trying to parse this VCARD file:
BEGIN:VCARD
VERSION:2.1
N;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:I;AM;DUMMY;;
TEL;CELL:123456789
END:VCARD
These are the python commands I used:
import vobject
f=open('sample.vcf','r')
vcf=vobject.readOne(f)
then I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Anaconda3\lib\site-packages\vobject\base.py", line 1129, in readOne
allowQP))
File "C:\Program Files\Anaconda3\lib\site-packages\vobject\base.py", line 1073, in readComponents
vline = textLineToContentLine(line, n)
File "C:\Program Files\Anaconda3\lib\site-packages\vobject\base.py", line 912, in textLineToContentLine
'lineNumber' : n})
File "C:\Program Files\Anaconda3\lib\site-packages\vobject\base.py", line 336, in __init__
self.value = self.value.decode('quoted-printable')
AttributeError: 'str' object has no attribute 'decode'
link for error log https://paste.fedoraproject.org/391670/46866724/
Python is showing that str
object has no attribute decode
.
Here is the code snippet in vobject package source code where error is occurring:
if 'ENCODING' in self.params:
if 'QUOTED-PRINTABLE' in self.params['ENCODING']:
qp = True
self.params['ENCODING'].remove('QUOTED-PRINTABLE')
if 0==len(self.params['ENCODING']):
del self.params['ENCODING']
if 'QUOTED-PRINTABLE' in self.singletonparams:
qp = True
self.singletonparams.remove('QUOTED-PRINTABLE')
if qp:
self.value = self.value.decode('quoted-printable')
By reading similar problems in stackoverflow I understand that vobject package is trying to decode an already decoded string.So i even tried converting vcf file to binary string and giving that as an input to vobject.readOne
.
binstr = f.read('sample.vcf','r').encode('utf-8')
x=vobject.readOne(binstr)
but it is not working.
What I have to do to successfully parse VCARD
file?
Please somebody help me...
EDIT:
Now I understand that this error is due to incompatibility of vobject
with python 3. Can I do any little hack to overcome this error?