michael-adler / sync-google-contacts

Automatically exported from code.google.com/p/sync-google-contacts
18 stars 12 forks source link

UnicodeEncodeError: 'charmap' codec can't encode character u'\u0107' #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. python.exe contacts-sync.py --user=user1 --user=user2 --private=Group1 
--private=Group2 --dry-run --debug

What is the expected output? What do you see instead?
Contact: "Contact123" (user1) is new
Contact: add "Contact123" (user2)
Contact: "AnotherContact" (user1) is new
Contact: add "AnotherContact" (user2)
Traceback (most recent call last):
  File "contacts-sync.py", line 817, in <module>
    main()
  File "contacts-sync.py", line 814, in main
    MergeContacts(users, contacts, pvt_groups)
  File "contacts-sync.py", line 584, in MergeContacts
    print "Contact: \"%s\" (%s) is new" % (name, users[i])
  File "c:\Python27\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u0107' in position
 23: character maps to <undefined>

What version of the product are you using? On what operating system?
On Windows 2003, Python 2.7

Please provide any additional information below.
Always returning the same error, same faulty character '\u0107', but always 
different contact before the error (first run, ContactABC, second time, 
ContactXYZ, etc..., never the same contact).

With the help of a friend, we tryied modifying the import sys at the beginning 
of the script:
import sys; reload(sys); sys.setdefaultencoding('utf-8')
But the error is still the same :(

Original issue reported on code.google.com by tyrel...@gmail.com on 18 Jul 2013 at 1:54

GoogleCodeExporter commented 9 years ago
I had a similar problem, so I modified the code:
print "Contact: \"%s\" (%s) is modified" % (name.encode('ascii', 'ignore'), 
users[i])

It's a hack, but it works.  The contacts with unicode characters are still 
synced properly, it's just that unicode character is dropped in the console 
output.

Original comment by rockmast...@gmail.com on 19 Apr 2014 at 11:47

GoogleCodeExporter commented 9 years ago
I think I fixed all the places that print fields that might have unicode data.

Original comment by mad...@tapil.com on 31 Dec 2014 at 6:22