Python problem in postgres on MAC

Asked

Viewed 17 times

0

Guys, I’m testing Trigger functions with python on Postgres and I’m having problems when I go to test on my Mac. Follow the function:

create function sendchange()
returns trigger
as $$
import requests
import json

url = "http://localhost:8080/send"
headers = {'Content-Type': 'application/json'}

payload = {'source': TD['args'][0], 'table': TD['args'][1], 'data': TD['new']}
r = requests.post(url, data=json.dumps(payload), headers=headers)
$$ language plpythonu;

And the creation of Trigger:

CREATE TRIGGER insertteste AFTER INSERT
ON processo FOR EACH ROW
EXECUTE PROCEDURE sendchange ('application','usuario');

It turns out that in windows environment, Trigger works without any problem. However when I test on Mac, it launches error:

SQL state: 38000
Context: Traceback (most recent call last):
PL/Python function "sendchange", line 2, in <module>
import requests
PL/Python function "sendchange"

I have no idea why this is happening in the Mac linux environment. This script is to send database data to another application.

  • 1

    in the error code, it seems that the module requests is not available for the python interpreter that Postgresql accesses.

  • This is the problem, I installed the requests module, but the execution of the python script from the database does not see this module. I don’t know if it is necessary to do any more configuration in the linux environment for plpythonu to access the dependencies. I have tested in windowns environment and had no problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.