Problem with plugin development in OctoPi

What is the problem?

I created a simple plugin that makes request to a web service when starting to print and when done printing to track print times. Everything works fine when installing though github archive link in plugin manager on my mac but when installing on the pi I get a strange error when making the requests. Below there is the octoprint.log. link for downloading plugin for testing https://github.com/sofokli1/OctoPrint-Toggl/archive/1.0.0.zip apitoken to use in plugin settings "bd18dcd3a8c511b976fb1e90ed84cc03"

What did you already try to solve it?

I tried to reinstall the plugin thought plugin manager and update pip but nothing changed.

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)

OctoPrint version : 1.3.9
OctoPi version : 0.15.1

Creality Ender 3

octoprint.log

2018-11-18 15:37:45,223 - octoprint.plugin - ERROR - Error while calling plugin toggl
Traceback (most recent call last):
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/__init__.py", line 225, in call_plugin
    result = getattr(plugin, method)(*args, **kwargs)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_toggl/__init__.py", line 69, in on_event
    self.startTimer(description)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_toggl/__init__.py", line 89, in startTimer
    toggl.startTimeEntry(description)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_toggl/TogglPy.py", line 146, in startTimeEntry
    response = self.postRequest(Endpoints.START_TIME, parameters=data)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_toggl/TogglPy.py", line 124, in postRequest
    Request(endpoint, data=binary_data, headers=self.headers, method=method), cafile=cafile
TypeError: __init__() got an unexpected keyword argument 'method'
2018-11-18 15:38:05,543 - octoprint.plugins.navbartemp - INFO - C

My guess is that you manually installed toggl on your Mac but you didn't include it in the dependencies. So when you did the install on the Raspberry, it didn't know to pip install toggl...?

Not really sure but maybe it goes in requirements.txt or on line 49 of setup.py.

I have manually removed TogglPy and the plugin and re-installed from the plugin manager many times. The logs form the plugin manger show both of them being installed. Will give line 49 a try. Thanks

The important thing to remember with respect to OctoPrint, Python and pip is that all this happens in a virtual environment. So you can't just easily pip install a dependency since that won't necessarily be under OctoPrint's virtual environment.

The easiest way to do this right—especially if you hope to publish the plugin—is to adjust the setup.py for the dependency. If you wanted to get it working for your Raspberry Pi's test rig, I think it's something like:

  1. remote into the Raspi
  2. source ~/oprint/bin/activate
  3. sudo service octoprint stop
  4. pip install TogglPy
  5. deactivate
  6. sudo reboot

Basically, you're turning on the virtual environment, stopping OctoPrint, installing TogglPy within the virtual environment, deactivating the virtual environment and then rebooting so that everything comes back up normally.

In theory, this would bring up OctoPrint with the dependency for your rig.

I manually uninstalled the plugin and the dependency in the venv and tried reinstalled from the manager. My main problem now is strange as well. It looks like when I import in the plugin __init__.py it is like it can't see the dependency so the import fails. Why might this be? If I go in python console in the venv I can do the same import just fine but my plugin gives the following error when loading:

2018-11-20 22:38:42,062 - octoprint.plugins.pluginmanager - INFO - Plugin to be installed from https://github.com/sofokli1/OctoPrint-Toggl/archive/1.0.0.zip was already installed, forcing a reinstall
2018-11-20 22:38:53,400 - octoprint.plugin.core - ERROR - Error loading plugin toggl
Traceback (most recent call last):
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/plugin/core.py", line 847, in _import_plugin
    instance = imp.load_module(key, f, filename, description)
  File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint_toggl/__init__.py", line 8, in <module>
    from toggl.TogglPy import Toggl
ImportError: No module named TogglPy

I stoped looking for a solution for this. I went with a work around (moved the needed code from the dependency into the plugin's __init__.py) work as it should now.

1 Like