Re: Problem with pl/python procedure connecting to the internet

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Igor Sosa Mayor <joseleopoldo1792(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with pl/python procedure connecting to the internet
Date: 2015-08-23 15:28:54
Message-ID: 55D9E6B6.4080703@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/23/2015 12:09 AM, Igor Sosa Mayor wrote:
> "Charles Clavadetscher" <clavadetscher(at)swisspug(dot)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.

I tried it here, using your functions, and could not get it to fail:

Running as postgres user.

test=# select version();
version

-----------------------------------------------------------------------------------------------------------------------------
PostgreSQL 9.4.2 on i686-pc-linux-gnu, compiled by gcc (SUSE Linux)
4.8.1 20130909 [gcc-4_8-branch revision 202388], 32-bit
(1 row)

Python 2. I did change the plpython2u to plpythonu in geocodificar as I
have only the one version of plpythonu installed.

test=# create table lat_long(ciudad text, pais text, latitute numeric
not null, longitude numeric not null);

create trigger lat_lon before insert or update on lat_long for each row
execute procedure anadirgeocoord();

test=# insert into lat_long (ciudad, pais) values ('Bellingham', 'USA');
INSERT 0 1
test=# insert into lat_long (ciudad, pais) values ('Seattle', 'USA');
INSERT 0 1
test=# insert into lat_long (ciudad, pais) values ('London', 'UK');
INSERT 0 1
test=# insert into lat_long (ciudad, pais) values ('Perth', 'AU');
INSERT 0 1
test=# select * from lat_long ;
ciudad | pais | latitute | longitude
------------+------+-------------+--------------
Bellingham | USA | 48.754402 | -122.4788602
Seattle | USA | 47.6038321 | -122.3300624
London | UK | 51.5073219 | -0.1276474
Perth | AU | -31.9527121 | 115.8604796
(4 rows)

test=# update lat_long set pais= 'UK' where ciudad ='Bellingham';
UPDATE 1
test=# select * from lat_long ;
ciudad | pais | latitute | longitude
------------+------+-------------+--------------
Seattle | USA | 47.6038321 | -122.3300624
London | UK | 51.5073219 | -0.1276474
Perth | AU | -31.9527121 | 115.8604796
Bellingham | UK | 55.1443709 | -2.2549272
(4 rows)

So it is something to do with the setup on your laptop.

>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Igor Sosa Mayor 2015-08-23 16:51:33 Re: Problem with pl/python procedure connecting to the internet
Previous Message Andy Colson 2015-08-23 14:45:50 Re: 9.5 beta pg_upgrade documentation