What does 'UnicodeError: ASCII decoding error: ordinal not in range(128)' and 'UnicodeError: ASCII encoding error: ordinal not in range(128)' mean?

These messages usually means that you’re trying to either mix Unicode strings with 8-bit strings, or is trying to write Unicode strings to an output file or device that only handles ASCII.

When you do this, Python will usually assume that the 8-bit string contains ASCII data only, and will raise an error if this is not the case.

The best way to avoid this on input is to convert all incoming strings to Unicode, do the processing in Unicode, and then convert back to encoded byte strings on the way out.

For this to work, you need to know what encoding to use. In most cases, you can get this information from the environment the application runs in. For example, a program that handles email or web input will typically find character set encodin