Sending POST request when an event is triggered using python requests package

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 file, in the following directory (senaite/senaite.core/blob/master/bika/lims/workflow/analysisrequest/ (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 when the after_publish is triggered.

Hi @Omar012

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
(python2.7) senaite@ridingbytes:~$ which pip
(python2.7) senaite@ridingbytes:~$ head senaite/bin/client1

import sys
sys.path[0:0] = [

you would need to install it for the Python interperter located at /home/senaite/python2.7/bin/python2.7.

So the final command would look like this:

/home/senaite/python2.7/bin/pip install requests

After that, you should be able to import requests.

Additional note: Coding directly into the senaite.core package is not recommended. Better write custom code in an add-on.

Best Regards

@ramonski Thank you so much, it worked like a charm. And I’ll look into working with add-ons soon