taxilian / OctoPrint-Twilio

Octoprint plugin for print completion notifications using Twilio (for free w/ trial account)
GNU Affero General Public License v3.0
5 stars 9 forks source link

After update to OctoPrint 1.4.0, OctoPrint-Twilio fails to notify #18

Closed egburr closed 4 years ago

egburr commented 4 years ago

After update to OctoPrint 1.4.0, OctoPrint-Twilio fails to notify.

From octoprint.log

2020-03-12 00:35:57,733 - octoprint.server - INFO - OctoPrint 1.4.0
2020-03-12 00:35:57,754 - octoprint.plugin.core - INFO - 18 plugin(s) registered with the system:
|  Action Command Prompt Support (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/action_command_prompt
|  python:
|      pip: 19.3.1
|      version: 2.7.16

2020-03-12 20:57:35,246 - octoprint.printer.standard.job - INFO - Print job done - origin: local, path: equipment_lid_0.2mm_PLA_MK3S_2h34m.gcode, owner: egburr
2020-03-12 20:57:35,408 - octoprint.util.comm - INFO - Changing monitoring state from "Finishing" to "Operational"
2020-03-12 20:57:36,763 - octoprint.plugins.tracking - INFO - Sent tracking event print_done, payload: {'origin': u'local', 'file': '532dbb377e1da30167b8740fba4ef38c1df74e52', u'elapsed': 9493}
2020-03-12 20:57:37,165 - octoprint.plugin - ERROR - Error while calling plugin smsnotifier
Traceback (most recent call last):
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/__init__.py", line 224, in call_plugin
    result = getattr(plugin, method)(*args, **kwargs)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_smsnotifier/__init__.py", line 90, in on_event
    return self._send_txt(payload)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_smsnotifier/__init__.py", line 94, in _send_txt
    filename = os.path.basename(payload["file"])
KeyError: 'file'
2020-03-12 21:05:58,498 - octoprint.server.heartbeat - INFO - Server heartbeat <3

I suspect the cause is related to this note in the changelog: https://octoprint.org/blog/2020/03/04/new-release-candidate-1.4.0/

Due to the new Python 3 compatibility there’s a heads-up for plugin authors:

This release officially adds support to run OctoPrint under Python 3 instead of 2, which has become EOL as of January 1st 2020. However, most third party plugins probably do not yet support Python 3. In order to allow Plugin Authors to test and if necessary adjust their plugins first before OctoPrint tries to load them under Python 3, a new plugin property __plugin_pythoncompat__ has been introduced. Plugins should define the compatibly Python version via this property which OctoPrint will check on load and only proceed with loading the plugin under Python 3 if it signals compatibility.

Additionally, the Plugin Repository has been expanded to include a new field compatibility.python which signals Python compatibility on the listing as well so that OctoPrint’s Plugin Manager will only show such plugins from the repository as installable under Python 3 which are configured as such.

Please see this guide in the documentation on how to go about compatibility testing and how to modify existing plugins to work with OctoPrint when running under Python 3.

By default, OctoPrint will assume compatibility to Python 2 only.

egburr commented 4 years ago

From an older octoprint.log priot to the 1.4.0 update: (SMS text through twilio was successful)

2020-03-10 03:27:56,167 - octoprint.server - INFO - OctoPrint 1.3.12
2020-03-10 03:27:56,190 - octoprint.plugin.core - INFO - 18 plugin(s) registered with the system:
|  Action Command Prompt Support (bundled) = /home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/action_command_prompt
|  python:
|    pip: 19.3.1
|    version: 2.7.16

2020-03-10 22:00:49,021 - octoprint.printer.standard.job - INFO - Print job done - origin: local, path: monsterHP_tray_0.2mm_PLA_MK3S_2h59m.gcode, owner: egburr
2020-03-10 22:00:49,224 - octoprint.util.comm - INFO - Changing monitoring state from "Finishing" to "Operational"
2020-03-10 22:00:51,252 - octoprint.plugins.tracking - INFO - Sent tracking event print_done, payload: {'origin': 'local', 'file': 'c9f8039062370471f012bd9b8a6dd87a05618acc', 'elapsed': 10784}
2020-03-10 22:00:53,149 - octoprint.plugins.smsnotifier - INFO - Print notification sent to +1XXXXXXXXXX
egburr commented 4 years ago

Before 1.4.0 update: payload: {'origin': 'local', 'file': 'c9f8039062370471f012bd9b8a6dd87a05618acc', 'elapsed': 10784} After 1.4.0 update: payload: {'origin': u'local', 'file': '532dbb377e1da30167b8740fba4ef38c1df74e52', u'elapsed': 9493} Notice the "u" in the local and elapsed keys, but not in the file key? But the error seems to be complaining about the file key. And this is what the server is sending to the plug-in if I understand it correctly. Unfortunately, I don't know python, so don't know what this means, but it's an obvious before/after difference I can see.

foosel commented 4 years ago

The problem is actually that this plugin is using an event payload key for PrintDone that has been marked as deprecated since 1.3.0 (as released on December 8th 2016) and was finally removed three years later in 1.4.0:

image

Easy fix would be to replace

filename = os.path.basename(payload["file"])

with

filename = payload["name"]
egburr commented 4 years ago

Yep, that fixes it on mine. Thanks! (had to wait for a 5 hour print that was in progress to complete before I could make the change to see)

taxilian commented 4 years ago

@egburr any chance you could submit a PR with that fix? I don't use the plugin anymore, but I can review and merge a pull request if you can tell me you've tested it

egburr commented 4 years ago

I have tested it such that I successfully installed my fork with the change, ran a print, and received the text notification that it completed. I have, hopefully correctly, submitted the PR for you.

taxilian commented 4 years ago

@foosel thanks so much for your help!

tedder commented 4 years ago

PR was #19; linking.