Re: Problem with pl/python procedure connecting to the internet - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Problem with pl/python procedure connecting to the internet
Date
Msg-id 55D9D8B5.1000304@aklaver.com
Whole thread Raw
In response to Re: Problem with pl/python procedure connecting to the internet  (Igor Sosa Mayor <joseleopoldo1792@gmail.com>)
List pgsql-general
On 08/23/2015 12:09 AM, Igor Sosa Mayor wrote:
> "Charles Clavadetscher" <clavadetscher@swisspug.org> writes:
>
>> Are you sure that you really use exactly the same code? The indication
>> "survice unknown" seems to point to an error in the URL and not to an
>> authorization problem. Maybe some encoding problem?
>
> THnaks for your hints.
>
> Yes, exactly the same code. Exactly the same query: two consoles, one
> with postgres, other with ipython. Postgres gives the error; ipython
> works.
>
>> The irritating thing is that you mention that it works sometimes and
>> sometimes not. Getting back to the encoding problem idea, is there a
>> difference if you call the function with a name containing special
>> characters (e.g. "é", "à", "ñ") or not?
>
> No special characters in the query. To be honest: it worked only 2-3
> times at work and I thought 'finally I managed to do it work'. But since
> then, it is not working anymore...
>
> In any case: I'm pretty sure it is a problem of postgres which is not
> able to make the connection. If I put a parameter timeout=15,
> postgres gives immediately the same error.

What happens if you run the function below directly in psql and not
through the trigger?

CREATE OR REPLACE FUNCTION geocodificar(direccion text)
          returns coordenadas
   AS $$
   from geopy.geocoders import Nominatim
   geoloc = Nominatim()
   location = geoloc.geocode(direccion)
   return(location.latitude, location.longitude)
   $$
   LANGUAGE 'plpython2u';

Hmm, just noticed plpython2u.

Do you have both Python 2 and Python 3 on this machine?

Did you create both the 2u and 3u variants of plpythonu?

>
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Martín Marqués
Date:
Subject: Re: master/master replication with load balancer in front
Next
From: s d
Date:
Subject: Re: Problem with pl/python procedure connecting to the internet