I tried to serve an html page that includes unicode text using django and received the following:
UnicodeDecodeError at /my_page.html
'utf8' codec can't decode bytes in position 28283-28287: unsupported Unicode code range
Request Method: GET
Request URL: http://mysite.com/my_page.html
Django Version: 1.2.4
Exception Type: UnicodeDecodeError
Exception Value:
'utf8' codec can't decode bytes in position 28283-28287: unsupported Unicode code range
Exception Location: /usr/local/lib/python2.6/encodings/utf_8.py in decode, line 16
Python Executable: /usr/local/bin/python
Python Version: 2.6.5
The page was generated by (please don’t kill me) MS Word, but when I saved it I made sure it was set to utf8. Also the file has the following tag in its heading:
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
I do need to keep the unicode as the page is not in English. What can I do so that django will present the page?
Why does django care and not simply give the browser to handle it?(locally the page is ok of course)
Could it be that it’s because django is trying to process this page as a template? I used the following in urls.py in order to redirect to the file itself:
(r'(.+).html$', 'django.views.generic.simple.direct_to_template'),
Are you sure the file is valid? It wouldn’t be the first time that MS Word produce invalid data. And if there are characters that aren’t valid Unicode, that would well explain this error. Have a look at the given bytes, if they are sensible.