Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeException in vcard_from_vobject #78

Open
tribut opened this issue Sep 3, 2013 · 7 comments
Open

AttributeException in vcard_from_vobject #78

tribut opened this issue Sep 3, 2013 · 7 comments

Comments

@tribut
Copy link

tribut commented Sep 3, 2013

Hi.

Using pycarddav 0.5.1 from pip I get the following exception trying to sync an owncloud 5.0.10 installation:

DEBUG:root:start syncing account owncloud
DEBUG:root:created version table
DEBUG:root:created accounts table
DEBUG:root:created owncloud table
DEBUG:root:getting /remote.php/carddav/addressbooks/foo/bar/141eb29ec8.vcf etag: "b4050229879ea875574ceecdf4b3a904"
[...]
DEBUG:root:getting /remote.php/carddav/addressbooks/foo/bar/056599fa37.vcf etag: "09caced6ccfd9cb1be41eb2ab332bc9a"
Traceback (most recent call last):
  File "/usr/local/bin/pycardsyncer", line 55, in <module>
    controllers.sync(conf)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/controllers.py", line 146, in sync
    my_dbtool.update(vcard, conf.account.name, href=href, etag=etag)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/backend.py", line 229, in update
    vcard = model.vcard_from_string(vcard)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/model.py", line 127, in vcard_from_string
    return vcard_from_vobject(vcard)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/model.py", line 101, in vcard_from_vobject
    line.transformFromNative()
  File "/usr/local/lib/python2.7/dist-packages/vobject/base.py", line 152, in transformFromNative
    return self.behavior.transformFromNative(self)
  File "/usr/local/lib/python2.7/dist-packages/vobject/vcard.py", line 298, in transformFromNative
    obj.value = serializeFields(obj.value)
  File "/usr/local/lib/python2.7/dist-packages/vobject/vcard.py", line 228, in serializeFields
    fields = [backslashEscape(val) for val in obj]
  File "/usr/local/lib/python2.7/dist-packages/vobject/base.py", line 1133, in backslashEscape
    s=s.replace("\\","\\\\").replace(";","\;").replace(",","\,")
vobject.base.NativeError: At line 7: In transformFromNative, unhandled exception: <type 'exceptions.AttributeError'>: 'list' object has no attribute 'replace'

I tried to re-add the except block removed in 4176b09#L0L681 but only got another exception:

DEBUG:root:getting /remote.php/carddav/addressbooks/foo/bar/056599fa37.vcf etag: "09caced6ccfd9cb1be41eb2ab332bc9a"
Traceback (most recent call last):
  File "/usr/local/bin/pycardsyncer", line 55, in <module>
    controllers.sync(conf)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/controllers.py", line 146, in sync
    my_dbtool.update(vcard, conf.account.name, href=href, etag=etag)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/backend.py", line 229, in update
    vcard = model.vcard_from_string(vcard)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/model.py", line 131, in vcard_from_string
    return vcard_from_vobject(vcard)
  File "/usr/local/lib/python2.7/dist-packages/pycarddav/model.py", line 116, in vcard_from_vobject
    property_value = (',').join(property_value)
TypeError: sequence item 0: expected string, list found

I'm using Python 2.7.3 from Debian wheezy.

@geier
Copy link
Owner

geier commented Sep 3, 2013

looks like vobject can't handle that vcard. I guess I'll wrap that function call and print failing vcards, so we might know what the problem is

geier added a commit that referenced this issue Sep 3, 2013
broken in a sense that vobject cannot parse them
these cards won't get inserted into the db, but instead a warning is
printed and, in debug mode, the whole vcard is printed.

this should 'take care' of cases like gh #78 for now
@geier
Copy link
Owner

geier commented Sep 3, 2013

could you check out pycarddav's develop branch, install it and try again? pycarddav should now print the vcard in case (and ignore it until next sync). You might want to paste the card (with all personal information redacted of course) or send it by email, so I can have a look at it.

@llucax
Copy link
Contributor

llucax commented Sep 16, 2013

I took a deeper look at the problem and it was a comma in an Organization field. I don't know if it's legal or not in VCARD, but the field gets split by commas and then the seriealizer is not expecting a list instead of a string. I sent an e-mail to the vobject mailing list about it but is waiting to be approved.

@geier
Copy link
Owner

geier commented Sep 16, 2013

I believe ',' and ';' must be escaped with a backslash ''

It would be nice if vobject would be a more forgiving. But since there seems to be hardly any development going on at vobject, I might switch to an icalendar based solution (if I find the time), since python 3 support would be awesome (which is not yet in icalendar, but they are working on it).

@geier
Copy link
Owner

geier commented Sep 17, 2013

not correctly escaped ',' might be an issue with VCards set up with owncloud owncloud/contacts#170

@llucax
Copy link
Contributor

llucax commented Sep 17, 2013

In model.py at function vcard_from_string(vcard_string), when printing the vcard_string, this is what I get for a contact that has a comma in the organization:

BEGIN:VCARD
VERSION:3.0
UID:87452b8b1e
PRODID:-//ownCloud//NONSGML Contacts 0.2.5//EN
REV:2013-09-17T21:11:21+00:00
FN:Test Man
N:Man;Test;;;
ORG:Test, Org
END:VCARD

I don't know if this is an owncloud problem or vobject (vobject doesn't seem to behave as it should anyway, it should handle malformed data with a graceful error, if owncloud is really sending wrong data).

@geier
Copy link
Owner

geier commented Sep 18, 2013

the RFC specifies that commas MUST be escaped, but you are right, vobject should at least handle that error more graceful (perhaps it can be configured to do that, I'll have to look into this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants