75👍
This is a bug in mimetypes
, triggered by bad data in the registry. (рєфшю/AMR
is not at all a valid MIME media type.)
ctype
is a registry key name returned by _winreg.EnumKey
, which mimetypes
is expecting to be a Unicode string, but it isn’t. Unlike _winreg.QueryValueEx
, EnumKey
returns a byte string (direct from the ANSI version of the Windows API; _winreg
in Python 2 doesn’t use the Unicode interfaces even though it returns Unicode strings, so it’ll never read non-ANSI characters correctly).
So the attempt to .encode
it fails with a UnicodeDecodeError trying to get a Unicode string before encoding it back to ASCII!
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass
These lines in mimetypes
should simply be removed.
ETA: added to bug tracker.
8👍
By the way, the main culpit of the problem is QuickTime which adds non-ascii mime types to the windows registry. The easiest way to fix it is to manually find and remove from the registry the subsections of the HKCR/Mime/Database/ContentType/
starting with аудио/
and видео/
.
- [Django]-Django: return string from view
- [Django]-How to store a dictionary on a Django Model?
- [Django]-Django ModelForm to have a hidden input
5👍
There is a patch:
http://bugs.python.org/file18143/9291.patch
Works great for me.
Just replace UnicodeEncodeError to be UnicodeError
- [Django]-Django FileField upload is not working for me
- [Django]-ValueError: Related model u'app.model' cannot be resolved
- [Django]-How can django sql queries use case insensitive and contains at the same time?
4👍
An alternative solution from python issue9291 by Alexandr Zarubkin (me21):
add file named sitecustomize.py in Lib\site-packages folder.
import sys
sys.setdefaultencoding("cp1251")
- [Django]-How does Django Know the Order to Render Form Fields?
- [Django]-About 20 models in 1 django app
- [Django]-How to get an array in Django posted via Ajax
1👍
its a python bug with latin MIME tipes in registry
start regedit and inspect “HKEY_CLASSES_ROOT\MIME\Database\Content Type” for non-latin names.
- [Django]-Django manage.py Unknown command: 'syncdb'
- [Django]-Django: Rest Framework authenticate header
- [Django]-Is APITest with Query params different then just normal url?