Wednesday, 11 September 2013

Python/Django unable to decode windows registry key

Python/Django unable to decode windows registry key

I'm trying to support a Windows user of a compiled python/django
application who is getting the following stacktrace when running the app;
Traceback (most recent call last):
File "django_offline\networkaccessmanager.pyc", line 69, in createRequest
File "django\contrib\staticfiles\handlers.pyc", line 58, in get_response
File "django\contrib\staticfiles\handlers.pyc", line 51, in serve
File "django\contrib\staticfiles\views.pyc", line 41, in serve
File "django\views\static.pyc", line 57, in serve
File "mimetypes.pyc", line 294, in guess_type
File "mimetypes.pyc", line 355, in init
File "mimetypes.pyc", line 259, in read_windows_registry
File "mimetypes.pyc", line 249, in enum_types
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa9 in position 28:
ordinal not in range(128)
The problem is in the following while loop where it tries to encode the
Content Type reg key;
def enum_types(mimedb):
i = 0
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
break
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass
else:
yield ctype
i += 1
I've never seen any issues with anything like this, so I'm out on a limb
here looking for suggestions :)
I've got an export of the problem area in the reg;
http://pastebin.com/fqygjBfj

No comments:

Post a Comment