Playing With Wire » internationalizationhttp://www.playingwithwire.com
The Internet Startup BlogWed, 20 Jul 2011 18:45:29 +0000en-UShourly1Zendesk Remote Authentication with Django and Unicode Nameshttp://www.playingwithwire.com/2009/06/zendesk-remote-authentication-with-django-and-unicode-names/
http://www.playingwithwire.com/2009/06/zendesk-remote-authentication-with-django-and-unicode-names/#commentsSat, 06 Jun 2009 17:16:22 +0000http://www.playingwithwire.com/?p=458Recently we hooked up with Zendesk for our support system. We hooked up its Remote Authentication API so that our customers could use their YippieMove logins in our support system as well. Jon Gales provided a great recipe for doing this in Django which we kicked off with, making some minor updates too. Only one problem remained: if an account had international characters in the first or the last name, Chinese, Japanese, and so on, the code would error out.

UnicodeEncodeError: 'ascii' codec can't encode character u'\xef' in position 2: ordinal not in range(128)

The problem is that md5().hexdigest() only works on byte strings. If you give it a unicode string it will try to .encode('ascii') it, which works fine as long as there are no international characters in the string.

The solution is simple: just explicitly UTF encode the source string. The Zendesk documentation did not mention what encoding they use themselves but my first guess would have been UTF-8, which turned out to be right. So with that in mind here is our current version of Jon Gales’ Zendesk Remote Authentication snippet for Django: