According calling external IPs, I used plpython3u extension for Postgres with success π
apt install postgresql-plpython3-15
CREATE EXTENSION plpython3u
CREATE OR REPLACE FUNCTION public.py_pgrest(uri text, body text DEFAULT NULL::text, content_type text DEFAULT 'application/json'::text)
RETURNS text
LANGUAGE plpython3u
AS $function$
from urllib.request import urlopen, URLError, HTTPError
try:
data = urlopen(uri)
except HTTPError as e:
return e
except URLError as e:
if hasattr(e, 'reason'):
return e.reason
elif hasattr(e, 'code'):
return e.code
else:
return e
else:
return data.read()
$function$
;
select public.py_pgrest('https://easygo.free.beeceptor.com/my/api/path'::text,'uhoh'::text, 'application/json'::text)```