OctoPrint-GCodeSystemCommands
OctoPrint-GCodeSystemCommands copied to clipboard
Fix logging exception which is thrown if command output contains non-ASCII characters
This pull request fixes an exception which was thrown when command produced output which contains non-ASCII characters.
Here is an example of the error before the fix:
Traceback (most recent call last):
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/util/comm.py", line 3332, in _process_command_phase
hook_results = hook(self, phase, command, command_type, gcode, subcode=subcode, tags=tags)
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_gcodesystemcommands/__init__.py", line 79, in hook_gcode_sending
self._logger.debug("Command ID %s returned: %s, output=%s" % (cmd_id, r, output))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 50: ordinal not in range(128)
And after:
2020-04-29 20:01:23,967 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID=907, Line=/home/pi/scripts/turn-off-printer.sh, Args=None
2020-04-29 20:01:23,976 - octoprint.plugins.gcodesystemcommands - INFO - Executing command ID: 907
2020-04-29 20:01:31,713 - octoprint.plugins.gcodesystemcommands - DEBUG - Command ID 907 returned: 0, output=Power: True
USB Power: None
Temperature: 46 °C
Load power: None
WiFi LED: None
Powering on
['ok']
2020-04-29 20:01:31,714 - octoprint.plugins.gcodesystemcommands - INFO - Command ID 907 returned: 0
I've tested it using Python 2.7 and Python 3.6.