On Wed, Apr 9, 2008 at 9:06 PM, Fridrik Mar Jonsson <[EMAIL PROTECTED]>
wrote:
>
> Hey fellow Djangorians,
>
> I've got an encoding problem with the latest checkout of Django. I
> just upgraded, on Mac OS X, from 0.96 over to the current SVN trunk.
> The migration worked well except for the fact that when I create an
> entry with the admin interface that makes use of an Icelandic
> character (like eth; \u00F0), editing the entry will yield the
> following traceback:
>
> === START OF TRACEBACK ===
>
> [traceback partially snipped]
>
> TemplateSyntaxError: Caught an exception while rendering: unknown
> encoding: mac-icelandic
>
> Original Traceback (most recent call last):
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/template/debug.py", line 71, in
> render_node
> result = node.render(context)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/template/debug.py", line 87, in render
> output = force_unicode(self.filter_expression.resolve(context))
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/template/__init__.py", line 542, in
> resolve
> new_obj = func(obj, *arg_vals)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/template/defaultfilters.py", line 627,
> in date
> return format(value, arg)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/utils/dateformat.py", line 263, in
> format
> df = DateFormat(value)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/utils/dateformat.py", line 114, in
> __init__
> self.timezone = LocalTimezone(dt)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/utils/tzinfo.py", line 36, in __init__
> self._tzname = self.tzname(dt)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/utils/tzinfo.py", line 55, in tzname
> return smart_unicode(time.tzname[self._isdst(dt)],
> DEFAULT_ENCODING)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/utils/encoding.py", line 37, in
> smart_unicode
> return force_unicode(s, encoding, strings_only, errors)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> python2.5/site-packages/django/utils/encoding.py", line 58, in
> force_unicode
> s = s.decode(encoding, errors)
> LookupError: unknown encoding: mac-icelandic
>
> === END OF TRACEBACK ===
>
> I've tried changing my locale by adding the following exports to
> my .bash_profile and then running a 'source':
>
> export LC_ALL=is_IS.UTF-8
> export LANG=is_IS.UTF-8
>
> I've also tried rebuilding the database with this new configuration,
> without success. I'm somewhat confused as to the source of this
> error, since none of my own files should have an encoding of 'mac-
> icelandic', and my understanding is that sqlite should be wise enough
> to use only UTF-8.
>
> I'd appreciate any help you could give me in troubleshooting this
> problem, at this point the slightest hint is immensely helpful.
>
Django is trying to use the system's default encoding to decode the time
zone name, so this actually has nothing to do with your database encoding.
It's an issue with Python and your system's default locale.
Before falling back to using the environment variable values to determine
default locale, Python tries to use _locale._getdefaultlocale() to determine
the default locale. Based on the fact that your setting the environment
variables doesn't fix the problem, I'm guessing your Python has a working
_locale module that supports _getdefaultlocale(). To confirm, open a Python
shell and try:
import _locale
_locale._getdefaultlocale()
If that works and returns 'mac-icelandic', no setting of environment
variables is going to fix the problem. Rather you'll have to change
whatever system setting is controlling what that call returns. On a Mac I
don't know what that is, though.
FWIW, from looking at the Python source I can tell you the C function it is
calling on the Mac to determine the system encoding is
CFStringGetSystemEncoding(). Interestingly, "mac-icelandic" is the one of
the strings returned by the function that calls CFStringGetSystemEncoding()
in a switch with the comment:
/* Return the code name for the encodings for which we have codecs. */
That comment would seem to imply that 'mac-icelandic' is an encoding that
Python should recognize, but your Python does not.
You are not the first person to run into this kind of trouble with Django's
attempt to use the default system encoding to decode the time zone name
string. I think the Django code was written with the assumption that the
encoding returned by locale.getdefaultlocale() would always be one that
Python had a codec for, but that doesn't seem to be the case. Perhaps the
Django code here should try to a codecs.lookup() for the default encoding
and fall back to ascii if the lookup fails.
Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---