Thread: Error with plpython

Error with plpython

From
Efraín Déctor
Date:
Hello.
 
Strange thing happening:
 
We rencently installed plpython in one of our test servers and installed an extension to use the google api (http://pypi.python.org/pypi/googlemaps ) , everything went fine we tested this function:
 
CREATE OR REPLACE FUNCTION google_reverse_geocode(lat numeric, lon numeric)
  RETURNS text AS
$BODY$
   
    from googlemaps import GoogleMaps
    gmaps= GoogleMaps()
    address =  gmaps.latlng_to_address(lat,lon)
    return (address)
$BODY$
  LANGUAGE plpythonu VOLATILE
  COST 100;
ALTER FUNCTION google_reverse_geocode(numeric, numeric)
  OWNER TO pgsql;
 
However, once we installed it on our production server that function doesnt work, it keeps sending this message:
 
ERROR:  ImportError: cannot import name SSLError
CONTEXT:  Traceback (most recent call last):
 
The strange thing is that our server are the same in everything so we don’t know why is failing in our production eviroment.
 
Thanks in advance.
 

Re: Error with plpython

From
Adrian Klaver
Date:
On 07/10/2012 02:59 PM, Efraín Déctor wrote:
> Hello.
> Strange thing happening:
> We rencently installed plpython in one of our test servers and installed
> an extension to use the google api
> (http://pypi.python.org/pypi/googlemaps) , everything went fine we
> tested this function:
> CREATE OR REPLACE FUNCTION google_reverse_geocode(lat numeric, lon numeric)
>    RETURNS text AS
> $BODY$
>      from googlemaps import GoogleMaps
>      gmaps= GoogleMaps()
>      address =  gmaps.latlng_to_address(lat,lon)
>      return (address)
> $BODY$
>    LANGUAGE plpythonu VOLATILE
>    COST 100;
> ALTER FUNCTION google_reverse_geocode(numeric, numeric)
>    OWNER TO pgsql;
> However, once we installed it on our production server that function
> doesnt work, it keeps sending this message:
> ERROR:  ImportError: cannot import name SSLError
> CONTEXT:  Traceback (most recent call last):
> The strange thing is that our server are the same in everything so we
> don’t know why is failing in our production eviroment.

At a guess something is not the same:)
1) Does SSLError exist on the production server
2) If it does exist, is it in the Python path?


> Thanks in advance.


--
Adrian Klaver
adrian.klaver@gmail.com



Re: Error with plpython

From
Efraín Déctor
Date:
We tested, the code directly into Python:

from googlemaps import GoogleMaps
gmaps= GoogleMaps()
address =  gmaps.latlng_to_address(18.835124317498853,-97.11448417315677)
repr(address)

And on both servers work without a problem. My guess is that something about
OpenSSL on the production server is not working with plpython. But I don't
know how to fix this.

Thanks

-----Mensaje original-----
From: Adrian Klaver
Sent: Tuesday, July 10, 2012 7:24 PM
To: Efraín Déctor
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Error with plpython

On 07/10/2012 02:59 PM, Efraín Déctor wrote:
> Hello.
> Strange thing happening:
> We rencently installed plpython in one of our test servers and installed
> an extension to use the google api
> (http://pypi.python.org/pypi/googlemaps) , everything went fine we
> tested this function:
> CREATE OR REPLACE FUNCTION google_reverse_geocode(lat numeric, lon
> numeric)
>    RETURNS text AS
> $BODY$
>      from googlemaps import GoogleMaps
>      gmaps= GoogleMaps()
>      address =  gmaps.latlng_to_address(lat,lon)
>      return (address)
> $BODY$
>    LANGUAGE plpythonu VOLATILE
>    COST 100;
> ALTER FUNCTION google_reverse_geocode(numeric, numeric)
>    OWNER TO pgsql;
> However, once we installed it on our production server that function
> doesnt work, it keeps sending this message:
> ERROR:  ImportError: cannot import name SSLError
> CONTEXT:  Traceback (most recent call last):
> The strange thing is that our server are the same in everything so we
> don’t know why is failing in our production eviroment.

At a guess something is not the same:)
1) Does SSLError exist on the production server
2) If it does exist, is it in the Python path?


> Thanks in advance.


--
Adrian Klaver
adrian.klaver@gmail.com



Re: Error with plpython

From
Adrian Klaver
Date:
On 07/10/2012 05:34 PM, Efraín Déctor wrote:
> We tested, the code directly into Python:
>
> from googlemaps import GoogleMaps
> gmaps= GoogleMaps()
> address =  gmaps.latlng_to_address(18.835124317498853,-97.11448417315677)
> repr(address)
>
> And on both servers work without a problem. My guess is that something
> about OpenSSL on the production server is not working with plpython. But
> I don't know how to fix this.

So in your function add the following to the beginning and see what it
returns on each server. More to the point is there a difference?:

import sys
plpy.notice(sys.path)

>
> Thanks

>


--
Adrian Klaver
adrian.klaver@gmail.com



Re: Error with plpython

From
Efraín Déctor
Date:
Hello. This is what returns the 2 servers:

Production Server:
['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-freebsd8',
'/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']

Test Server:
['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-freebsd9',
'/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']

Craig: Sorry about the details.

This is what we got:

Production server:
FreeBSD 8.2
Postgresql 9.1.2
Python 2.7.3 (default, Jul 10 2012, 21:36:33)

Test server:
FreeBSD 9
Postgresql 9.1.3
Python 2.7.2 (default, Mar 26 2012, 18:07:58)

We tested on other server (it worked) that use
FreeBSD 8.3
Python 2.6.8 (unknown, Jul  4 2012, 00:49:01)
PostgreSQL 9.1.3

Thank you

On 07/10/2012 05:34 PM, Efraín Déctor wrote:
> We tested, the code directly into Python:
>
> from googlemaps import GoogleMaps
> gmaps= GoogleMaps()
> address =  gmaps.latlng_to_address(18.835124317498853,-97.11448417315677)
> repr(address)
>
> And on both servers work without a problem. My guess is that something
> about OpenSSL on the production server is not working with plpython. But
> I don't know how to fix this.

So in your function add the following to the beginning and see what it
returns on each server. More to the point is there a difference?:

import sys
plpy.notice(sys.path)

>
> Thanks

>


--
Adrian Klaver
adrian.klaver@gmail.com



-----Mensaje original-----
From: Craig Ringer
Sent: Tuesday, July 10, 2012 10:43 PM
To: Efraín Déctor
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Error with plpython

On 07/11/2012 06:16 AM, Efraín Déctor wrote:
> However, once we installed it on our production server that function
> doesnt work, it keeps sending this message:
> ERROR:  ImportError: cannot import name SSLError
> CONTEXT:  Traceback (most recent call last):
> The strange thing is that our server are the same in everything so we don’t
> know why is failing in our production eviroment.

I'm guessing it isn't really the same.

You're probably missing a library that Python's SSL support requires,
missing some Python modules, or have a library that isn't compatible
with the one Python's SSL support was built against.

Since you've neglected to describe your client or server environments at
all, it's hard to say more.

--




Re: Error with plpython

From
Adrian Klaver
Date:
On 07/11/2012 06:32 AM, Efraín Déctor wrote:
> Hello. This is what returns the 2 servers:
>
> Production Server:
> ['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
> '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
> '/usr/local/lib/python2.7/plat-freebsd8',
> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> '/usr/local/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/site-packages']
>
> Test Server:
> ['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
> '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
> '/usr/local/lib/python2.7/plat-freebsd9',
> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> '/usr/local/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/site-packages']
>
> Craig: Sorry about the details.
>
> This is what we got:
>
> Production server:
> FreeBSD 8.2
> Postgresql 9.1.2
> Python 2.7.3 (default, Jul 10 2012, 21:36:33)
>
> Test server:
> FreeBSD 9
> Postgresql 9.1.3
> Python 2.7.2 (default, Mar 26 2012, 18:07:58)
>
> We tested on other server (it worked) that use
> FreeBSD 8.3
> Python 2.6.8 (unknown, Jul  4 2012, 00:49:01)
> PostgreSQL 9.1.3

Well both Postgres servers that worked are 9.1.3. From the release notes
for 9.1.3:

Allow use of threaded Python on FreeBSD (Chris Rees)

Our configure script previously believed that this combination wouldn't
work; but FreeBSD fixed the problem, so remove that error check.

Not sure if this has anything to do with what you are seeing, but it
might worth it to bump the production server to 9.1.3, if possible.

>
> Thank you
>



--
Adrian Klaver
adrian.klaver@gmail.com



Re: Error with plpython

From
Efraín Déctor
Date:
Hello.

It is possible to upgrade without any downtime?.

Thank you.

-----Mensaje original-----
From: Adrian Klaver
Sent: Wednesday, July 11, 2012 3:01 PM
To: Efraín Déctor
Cc: Craig Ringer ; pgsql-general@postgresql.org
Subject: Re: [GENERAL] Error with plpython

On 07/11/2012 06:32 AM, Efraín Déctor wrote:
> Hello. This is what returns the 2 servers:
>
> Production Server:
> ['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
> '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
> '/usr/local/lib/python2.7/plat-freebsd8',
> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> '/usr/local/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/site-packages']
>
> Test Server:
> ['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
> '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
> '/usr/local/lib/python2.7/plat-freebsd9',
> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> '/usr/local/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/site-packages']
>
> Craig: Sorry about the details.
>
> This is what we got:
>
> Production server:
> FreeBSD 8.2
> Postgresql 9.1.2
> Python 2.7.3 (default, Jul 10 2012, 21:36:33)
>
> Test server:
> FreeBSD 9
> Postgresql 9.1.3
> Python 2.7.2 (default, Mar 26 2012, 18:07:58)
>
> We tested on other server (it worked) that use
> FreeBSD 8.3
> Python 2.6.8 (unknown, Jul  4 2012, 00:49:01)
> PostgreSQL 9.1.3

Well both Postgres servers that worked are 9.1.3. From the release notes
for 9.1.3:

Allow use of threaded Python on FreeBSD (Chris Rees)

Our configure script previously believed that this combination wouldn't
work; but FreeBSD fixed the problem, so remove that error check.

Not sure if this has anything to do with what you are seeing, but it
might worth it to bump the production server to 9.1.3, if possible.

>
> Thank you
>



--
Adrian Klaver
adrian.klaver@gmail.com



Re: Error with plpython

From
Adrian Klaver
Date:
On 07/11/2012 04:17 PM, Efraín Déctor wrote:
> Hello.
>
> It is possible to upgrade without any downtime?.

It it is problem you may want to confirm the Postgres version is a
problem by setting up an 9.1.2 instance on your development machine and
seeing if the error shows up.

Otherwise that can be a complicated answer. I have not done it, though
with replication and pooling I understand it can be done. For a minor
version upgrade I can keep the downtime to under a minute. I install
from source and do something along lines of:

1)make
2)Then as postgres user pg_ctl stop
3) sudo make install
4)As postgres user again pg_ctl start

Not sure how things work on FreeBSD, especially if you are using some
sort of binary install.



>
> Thank you.



--
Adrian Klaver
adrian.klaver@gmail.com



Re: Error with plpython

From
Craig Ringer
Date:
On 07/11/2012 09:32 PM, Efraín Déctor wrote:
> Hello. This is what returns the 2 servers:
>
> Production Server:
> ['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
> '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
> '/usr/local/lib/python2.7/plat-freebsd8',
> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> '/usr/local/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/site-packages']
>
> Test Server:
> ['/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
> '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7',
> '/usr/local/lib/python2.7/plat-freebsd9',
> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> '/usr/local/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/site-packages']
>
> Craig: Sorry about the details.
>
> This is what we got:
>
> Production server:
> FreeBSD 8.2
> Postgresql 9.1.2
> Python 2.7.3 (default, Jul 10 2012, 21:36:33)

Interesting that your production server has the oldest FreeBSD and the
newest Python. I'm still suspecting a library mismatch of some kind.

Is there anything vaguely informative in PostgreSQL's log files after
the error? I'm hoping for a message from Python about a dlopen() or
dlsym() error, or for a message from the dynamic linker.

If you redirect the postmaster's stderr to a file, it's possible dynamic
linker messages might appear there but not be captured by Pg for
logging. I don't see how you'd redirect that without stopping and
starting the server, which you don't want to do.

--
Craig Ringer