KevinHorvatin / google-apps-for-your-domain-ldap-sync

Automatically exported from code.google.com/p/google-apps-for-your-domain-ldap-sync
0 stars 0 forks source link

error: ProvisioningApiError: **Error: : 'ascii' codec can't decode... #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Having a user with non-ascii characters in name or surname
2.Use the command syncOneUser add that user
3.

What is the expected output? What do you see instead?

I see this output:

Command: syncOneUser (uid=ivan)
The user record for uid=ivan,ou=personas,dc=cyc,dc=ull,dc=es is now:
Now looking up 'ivan' in Google Apps for Your Domain...
User 'ivan' not found
The recommended action for this user is to
treat user as having been: added

Proceed with that action (y/n) y
03-15 21:30 root         ERROR    error: ProvisioningApiError: 
**Error: : 'ascii' codec can't decode byte 0xc3 in position 2: ordinal 
not in range(128)
03-15 21:30 root         ERROR    failure to handle 'added' on 
uid=ivan,ou=personas,dc=cyc,dc=ull,dc=es: ProvisioningApiError: 
**Error: : 'ascii' codec can't decode byte 0xc3 in position 2: ordinal 
not in range(128)

and only if I'm using a XML file then I can see the next output before 
exit:

 Command: stop
Stopping
Update your config file isaatc_ull_es.cfg (y/n)n
Traceback (most recent call last):
  File "/usr/local/share/gafyd-ldap-sync/sync_ldap.py", line 178, in ?
    (config, ldap_context, user_database, google_context, log_config) = \
  File "/usr/local/share/gafyd-ldap-sync/sync_ldap.py", line 147, in 
DoMain
    user_database.WriteDataFile(options.data_file)
  File "/usr/local/share/gafyd-ldap-sync/userdb.py", line 612, in 
WriteDataFile
    self._WriteXMLFile(fname, dns)
  File "/usr/local/share/gafyd-ldap-sync/userdb.py", line 1104, in 
_WriteXMLFile
    f.write(doc.toprettyxml(encoding="utf-8"))
  File "/usr/lib/python2.4/codecs.py", line 501, in write
    return self.writer.write(data)
  File "/usr/lib/python2.4/codecs.py", line 178, in write
    data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 198: 
ordinal not in range(128)

What version of the product are you using? On what operating system?

Google Apps LDAP Sync v1.2. Linux

Please provide any additional information below.

The expception ProvisioningApiError is raised in _ToXML() method, inside 
provisioning_backend.py (Google Apps Provisioning API 1.0). I do some 
test to the API trying to insolate the problem.

I saw the same error after invoke the next sentence:

api.CreateAccountWithEmail("tést", "test", "test", "test")

but the next sentence works fine:

api.CreateAccountWithEmail(u"tést", "test", "test", "test")

It happens because the API must convert the arguments to unicode (using 
unicode()) to compose the XML that must be sended in the request to 
Google. For arguments that already are unicode strings (see the first 
argument y the second sentence) nothing happens. But for arguments that 
are byte strings with non-ascii characters an exception is raised.

A hack would be to set the default encoding in site.py to utf-8. But many 
people say that it is a bad trick. The good solution could be only use 
unicode strings inside the "application", invoke Google Apps Provisioning 
API using that unicode strings and only convert them to byte strings 
(with str()) before and after I/O. Many other packages (like 
LDAPUserFolder for Zope) do that to solve all the problems with the 
enconding.

Original issue reported on code.google.com by aplatan...@gulic.org on 15 Mar 2008 at 10:38

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I attach a patch. It solves this problem but I think it isn't the best 
solution. 

Original comment by aplatan...@gulic.org on 19 Mar 2008 at 5:02

Attachments: