TAGS :Viewed: 8 - Published at: a few seconds ago

import CGIHTTPServer results UnicodeDecodeError on Python 2.7.6.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\CGIHTTPServer.py", line 30, in <module>
    import SimpleHTTPServer
  File "C:\Python27\lib\SimpleHTTPServer.py", line 27, in <module>
    class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  File "C:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHand
    mimetypes.init() # try to read system mime.types
  File "C:\Python27\lib\mimetypes.py", line 358, in init
  File "C:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "C:\Python27\lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
 UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 0: ordinal
 not in range(128)" 

Please advise me.

Answer 1

This is a bug in Python 2.7, reported as issue 21138; the mimetypes module doesn't use the correct encoding for Unicode mimetypes in the Windows registry.

The bug ticket contains a work-around; you'll have to edit mimetypes.py.