| Reply | « Previous Thread | Next Thread » |
|
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'))
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)
Thanks for your time & bye, Joost |
|
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. |
| simo.salminen |
| View Public Profile |
| Find all posts by simo.salminen |
|
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 |
|
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(..) |
| simo.salminen |
| View Public Profile |
| Find all posts by simo.salminen |
|
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |