I cannot install/uninstall/update plugins, update OctoPrint, or restore a backup, I get a "UnicodeEncodeError: 'latin-1' codec can't encode characters"

If you are trying to install, uninstall or update plugins, update OctoPrint itself, or restore from a backup (which also involves installing plugins), and are encountering an error along the lines of this:

2022-01-31 14:53:41,423 - octoprint.plugins.softwareupdate - ERROR - Update of DisplayLayerProgress can not be performed, please also check plugin_softwareupdate_console.log for possible causes of this
Traceback (most recent call last):
[...]
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/commandline.py", line 57, in clean_ansi
    return _ANSI_REGEX.sub(b"", line.encode("latin1")).decode("latin1")
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 5-44: ordinal not in range(256)

you are running into an incompatibility issue between OctoPrint and latest pip 22+ which causes this. A fix is available and will be released with OctoPrint 1.8.0. In the meantime please downgrade pip to 21.3.1 which still works fine with stable versions of OctoPrint prior to 1.8.0.

Downgrade pip via helper plugin

A helper plugin that downgrades pip for you can be found here. Follow the usage instructions precisely!

Downgrade pip via command line

On OctoPi, SSH into your Pi, then on the command line run

~/oprint/bin/pip install pip==21.3.1

On a manual install, substitute accordingly with the pip of the virtualenv OctoPrint is installed in. On Windows, you'll need to run python -m pip install pip==21.3.1.


Alternative: Backported fix

A backport of the fix from 1.8.0 has been made available in form of a single-file plugin here.


Background

pip 22 was released after the release of OctoPrint 1.7.3. pip isn't updated automatically by default unless you opt into this through a setting in Software Update or update it manually via the command line, so most users are likely not affected by this issue. Thus I made the decision against a hotfix release as that would have bound valuable time that's needed for getting 1.8.0 on the road.

3 Likes