You Are Here:

Community: Developer Discussion Boards

#1 Old Encoding Problem with VCardImport - 2005-09-27, 21:35

Join Date: Jun 2005
Posts: 16
sx1freak
Offline
Registered User
Hi,

when I want to import a VCard with German umlauts with this code
Code:
import contacts

vcardstring=u"""
BEGIN:VCARD
CLASS:PUBLIC
FN:öäüÖÄÜ
REV:2005-09-23T16:05:40Z
UID:uTPLCgYuJe
VERSION:3.0
END:VCARD"""

contactdb = contacts.open()
print vcardstring.encode('iso-8859-1','replace')
contactdb.import_vcards(vcardstring.encode('iso-8859-1','replace'))
I get this error:
Code:
BEGIN:VCARD
CLASS:PUBLIC
FN:öäüÖÄÜ
REV:2005-09-23T16:05:40Z
UID:uTPLCgYuJe
VERSION:3.0
END:VCARD

Traceback (most recent call last):
  File "E:\System\Apps\Python\my\syncandrunclient.py", line 156, in run
    execfile(target, g)
  File "e:\python\vcardtest.py", line 15, in ?
    TEL;TYPE=WORK:5678
  File "E:\system\libs\contacts.py", line 157, in import_vcards
    return [self[x] for x in self._db.import_vcards(unicode(vcards),vcard_flags)]
UnicodeError: ASCII decoding error: ordinal not in range(128)
Please give me a hint where my error lies! I really need this...
Thanks for your time & bye,

Joost
Reply With Quote

#2 Old Re: Encoding Problem with VCardImport - 2005-09-28, 15:39

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
The code inside contacts.py only supports pure ascii strings.

Workaround: call the importing code manually. Take a look at contacts.py, and make similar call, only remove the unicode(vcards) stuff. Then pass vcards unicode string.

Or, if you insist on using the call, you have to use u"something".encode("ascii", "replace"). Then you will loose the special characters.
Reply With Quote

#3 Old Re: Encoding Problem with VCardImport - 2005-09-29, 10:10

Join Date: Jun 2005
Posts: 16
sx1freak
Offline
Registered User
Hi,
thanks for your reply! To be honest, I'm quite surprised I can only import ascii-charcters in an easy way, that seems not to be very useful for many many users out there...I really hope this restriction gets lifted at some point.

Back to your suggestion: wouldn't it be possible then to edit contacts.py directly and remove the unicode()?

Bye,

Joost
Reply With Quote

#4 Old Re: Encoding Problem with VCardImport - 2005-09-29, 10:14

Join Date: Aug 2004
Posts: 290
simo.salminen
Offline
Regular Contributor
Sure it is. But you don't have to do that. Just copy/paste the routine code from contacts.py, and do the call in your code. That's cleaner than modifying librarys.

so your code looks like: contactsdb._db.import_vcards(..)
Reply With Quote

#5 Old 2005-09-29, 15:33

Join Date: Jun 2005
Posts: 16
sx1freak
Offline
Registered User
Whooo, thanks!
I just tried the in-place replacement, and it works! Thanks a lot!
Now I'm going to try the replacement in my code, as you suggested.
Cool!

Bye, Joost

PS: I still cannot see why there is something in the code which (as far as I can see) deliberately disables important functionality...
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
problem when stop playing video on 3650 and try to play again niko86 Mobile Java General 5 2007-08-03 08:40
netcards - Problem with opening adapter kernj Symbian Tools & SDKs 5 2007-01-10 09:56
wireless problem sash_mca General Browsing 0 2003-06-06 12:34
Problem encoding Latin extra characters erand1972 General Messaging 1 2003-05-02 11:05
Problem Displaying Xhtml Mp Page With Greek Encoding manolis2 Browsing and Mark-ups 1 2003-04-15 23:11

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia