Django UnicodeDecodeError:asciicodec can't decode byte 0xe0 in position 0: ordinal not in range(128)
在我的一台机器上,当我使用google apps engine或django时,出现了错误.
例如:
-
app.yaml
application: demas1252c version: 1 runtime: python api_version: 1 handlers: - url: /images static_dir: images - url: /css static_dir: css - url: /js static_dir: js - url: /.* script: Demas125c.py
-
Demas125c.py
import cgi import wsgiref.handlers from google.appengine.ext.webapp import template from google.appengine.ext import webapp class MainPage(webapp.RequestHandler): def get(self): values = {'id' : 10} self.response.out.write(template.render('福托.html', values)) application = webapp.WSGIApplication([('/', MainPage)], debug = True) wsgiref.handlers.CGIHandler().run(application)
-
福托.html
<!DOCTYPE html> <html lang="en"> <head></head> <body>some</body> </html>
错误消息:
C:\artefacts\dev\project>"c:\Program Files\Google\google_appengine\dev_appserver.py" foto-hosting
Traceback (most recent call last):
File "c:\Program Files\Google\google_appengine\dev_appserver.py", line 69, in <module>
run_file(__file__, globals())
File "c:\Program Files\Google\google_appengine\dev_appserver.py", line 65, in run_file
execfile(script_path, globals_)
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_main.py", line 92, in <module>
from google.appengine.tools import dev_appserver
File "c:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 140, in <module>
mimetypes.add_type(mime_type, '.' + ext)
File "C:\Python27\lib\mimetypes.py", line 344, in add_type
init()
File "C:\Python27\lib\mimetypes.py", line 355, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 260, in read_windows_registry
for ctype in enum_types(mimedb):
File "C:\Python27\lib\mimetypes.py", line 250, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
当我在django中使用静态文件(没有gae)时,我有非常类似的错误(使用不同的堆栈).
我试图找到错误的原因,并向mimetypes添加了代码.py:
print '====='
print ctype
ctype = ctype.encode(default_encoding) # omit in 3.x!
然后我会在控制台中收到下一条消息:
=====
video/x-ms-wvx
=====
video/x-msvideo
=====
рєфшю/AMR
Traceback (most recent call last):
在注册表HKCR/Mime/Database/contentType/i中,有五个带有俄语(Cyrilic)字母的键.但是我怎样才能修复这个错误呢?