UnicodeDecodeError : 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)

前端 未结 5 1450
醉梦人生
醉梦人生 2020-11-29 20:20

On one of my machines I have the error when I am working with google apps engine or django.

For example:

  • app.yaml

    application: demas         
    
    
            
5条回答
  •  天命终不由人
    2020-11-29 21:02

    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 Unicode​Decode​Error 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.

提交回复
热议问题