Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 2
    Can you include a complete example that produces this error? Commented Apr 21, 2016 at 8:27
  • 1
    Is your source code written in utf-16 encoding ? Check with file abc.py. Commented Apr 21, 2016 at 8:29
  • 2
    Do not use sys.setdefaultencoding(). You are trying to auto-set broken bones there rather than not break your bones in the first place. Read nedbatchelder.com/text/unipain.html instead and handle Unicode properly. Commented Apr 21, 2016 at 8:36
  • 2
    Note that Python source code encoding can't handle anything but single-byte and UTF-8 codecs. UTF-16 and UTF-32 are not supported. Commented Apr 21, 2016 at 8:38
  • 3
    If you are handling data, there is no need to declare a source code encoding. That is only needed if you need to specify non-ASCII string literals in your code, but you could just use \xhh or \uhhhh escape sequences in those literals instead. A source code encoding declaration won't help with encoding and decoding data in your program. Commented Apr 21, 2016 at 8:40