I am trying to get Senaite to send the analysis report (pdf) through a POST request to another API, I did so by appending code inside the after_publish method in events.py file, in the following directory (senaite/senaite.core/blob/master/bika/lims/workflow/analysisrequest/events.py) (see attached image) the problem I am facing is that python requests package doesn’t work when I try to use it or even import it. I tried adding it to the eggs in buildout.cfg but that didn’t help either. any idea on how to overcome this problem. or if there’s a better approach to send a POST request with a file inside the events.py when the after_publish is triggered.
You need to install the requests package for the Python interpreter that is used for your Senaite installation.
For example in the following setup:
(python2.7) senaite@ridingbytes:~$ which python /home/senaite/python2.7/bin/python (python2.7) senaite@ridingbytes:~$ which pip /home/senaite/python2.7/bin/pip (python2.7) senaite@ridingbytes:~$ head senaite/bin/client1 #!/home/senaite/python2.7/bin/python2.7 import sys sys.path[0:0] = [ '/home/senaite/buildout-cache/eggs/Plone-4.3.19-py2.7.egg', '/home/senaite/buildout-cache/eggs/Pillow-3.3.3-py2.7-linux-x86_64.egg', '/home/senaite/buildout-cache/eggs/five.z2monitor-0.2-py2.7.egg', '/home/senaite/buildout-cache/eggs/Products.PloneHotfix20200121-1.1-py2.7.egg', '/home/senaite/senaite/src/demo.lims/src', '/home/senaite/senaite/src/senaite.core',
you would need to install it for the Python interperter located at
So the final command would look like this:
/home/senaite/python2.7/bin/pip install requests
After that, you should be able to
Additional note: Coding directly into the
senaite.core package is not recommended. Better write custom code in an add-on.
@ramonski Thank you so much, it worked like a charm. And I’ll look into working with add-ons soon