UnicodeDecodeError in gcode.py [New Install]

Basic Information:

Printer Model: Ender 3 v2
MCU / Printerboard: STM32F103
klippy.log
OctoPi: v0.18.0
OctoPrint: v1.8.4

Fill out above information and in all cases attach your klippy.log file. Pasting your printer.cfg is not needed

Describe your issue:

I have a new Klipper installation that I setup on an existing OctoPi instance and I’ve been following the guide on the Klipper website. I ran apt update and sudo apt upgrade prior to installation of Klipper. After getting to the “Configuring OctoPrint to use Klipper” section, I configured the settings as described and attempted to connect from OctoPrint. The connection timed out trying to connect to the /tmp/printer serial port.

After looking in /tmp/klippy.log, I saw the following:

Unable to open config file /home/pi/printer.cfg
Traceback (most recent call last):
  File "/home/pi/klipper/klippy/configfile.py", line 154, in _read_config_file
    f = open(filename, 'r')
IOError: [Errno 2] No such file or directory: '/home/pi/printer.cfg'
Config error
Traceback (most recent call last):
  File "/home/pi/klipper/klippy/klippy.py", line 175, in _connect
    self._read_config()
  File "/home/pi/klipper/klippy/klippy.py", line 134, in _read_config
    config = pconfig.read_main_config()
  File "/home/pi/klipper/klippy/configfile.py", line 275, in read_main_config
    data = self._read_config_file(filename)
  File "/home/pi/klipper/klippy/configfile.py", line 160, in _read_config_file
    raise error(msg)
Error: Unable to open config file /home/pi/printer.cfg
Read g-code
Traceback (most recent call last):
  File "/home/pi/klipper/klippy/gcode.py", line 400, in _process_data
    data = str(os.read(self.fd, 4096).decode())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
... [repeated for each handshake attempt]
Read g-code
Traceback (most recent call last):
  File "/home/pi/klipper/klippy/gcode.py", line 400, in _process_data
    data = str(os.read(self.fd, 4096).decode())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

The installation instruction don’t tell you to setup the config file until after the initial connection, but I went ahead and copied the printer-creality-ender3-v2-2020.cfg file from ~/klipper/config/ to ~/printer.cfg. After restarting the Klipper service, I was now only receiving the following error:

Read g-code
Traceback (most recent call last):
  File "/home/pi/klipper/klippy/gcode.py", line 400, in _process_data
    data = str(os.read(self.fd, 4096).decode())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

I found an existing discussion here about a similar error, but none of the solutions there have made any difference.

Here is the terminal output from OctoPrint:

Changing monitoring state from "Offline" to "Detecting serial connection"
Performing autodetection with 7 port/baudrate candidates: /tmp/printer@115200, /tmp/printer@250000, /tmp/printer@230400, /tmp/printer@57600, /tmp/printer@38400, /tmp/printer@19200, /tmp/printer@9600
Trying port /tmp/printer, baudrate 115200
Handshake attempt #1 with timeout 2.0s
Connected to: PackingSerial<id=0xb23b4170, open=True>(port='/tmp/printer', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=2.0, xonxoff=False, rtscts=False, dsrdtr=False), starting monitor
Send: N0 M110 N0*125
Handshake attempt #2 with timeout 2.0s
Send: N0 M110 N0*125
...
Connection closed, closing down monitor
Closing down send loop

klippy.log (2.7 KB)

See Help virtual_sdcard dispatch - #2 by Sineos

I’m not yet loading a gcode file to attempt to print (can’t load it until after connecting), so I’m not sure where non-ascii characters would come from. I receive this error while trying to initially connect and it seems the only gcode sent is N0 M110 N0*125. I checked this output from the terminal for non-printable characters and there are not any (maybe they don’t show in the terminal?). I also don’t have any GCODE scripts in the “After serial connection to printer is established” section.

  1. Post you original printer.cfg
  2. Remove any gcode under GCODE scripts

I had GCODE scripts in “After print job is cancelled”, “After print job is paused”, and “Before print job is resumed” in OctoPrint and have removed them. I still receive the same error afterwards.

I’ve attached my printer.cfg file, which is just of copy of ~/klipper/config/printer-creality-ender3-v2-2020.cfg.

printer.cfg (2.0 KB)

I’ve discovered my issue. I had the MeatPack plugin installed in my OctoPrint instance. After disabling this plugin, I’m able to connect successfully.

Thanks for your help @Sineos.

1 Like