Thread: Psycopg2 : error message.

Psycopg2 : error message.

From
image
Date:
Dear all,

I'm writing a python script for a web service. I have to connect to my
postgres/postgis databases via Psycopg2.

I writed a little first script just to connect to my pg/postgis db and drop
a test db.

But when i execute the python file, i have several error messages.

Please read the 2 usefull files below :

pg_test.py
<http://postgresql.1045698.n5.nabble.com/file/n5804197/pg_test.py>

SS_dos.JPG
<http://postgresql.1045698.n5.nabble.com/file/n5804197/SS_dos.JPG>


In advance, thank you to throw light for me.

Regards.

IMAGE



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: Psycopg2 : error message.

From
Dorian Hoxha
Date:
Try to use:

dont catch the exception when you make the connection, to see the right error

because: "i am unable to connect" may mean different things:  1.wrong user 2.wrong pass 3.server down etc


On Fri, May 16, 2014 at 12:12 PM, image <lcelati@latitude-geosystems.com> wrote:
Dear all,

I'm writing a python script for a web service. I have to connect to my
postgres/postgis databases via Psycopg2.

I writed a little first script just to connect to my pg/postgis db and drop
a test db.

But when i execute the python file, i have several error messages.

Please read the 2 usefull files below :

pg_test.py
<http://postgresql.1045698.n5.nabble.com/file/n5804197/pg_test.py>

SS_dos.JPG
<http://postgresql.1045698.n5.nabble.com/file/n5804197/SS_dos.JPG>


In advance, thank you to throw light for me.

Regards.

IMAGE



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: Psycopg2 : error message.

From
image
Date:
Hello,

Thanks. Ok i deleted the except. Please find below the 2 updates usefull
liles :

pg_test.py
<http://postgresql.1045698.n5.nabble.com/file/n5804203/pg_test.py>

SS_dos.JPG
<http://postgresql.1045698.n5.nabble.com/file/n5804203/SS_dos.JPG>


In advance, thank you.

Regards.

IMAGE.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804203.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: Psycopg2 : error message.

From
Dorian Hoxha
Date:
Also remove the first "try" + remove the space before "conn=" so you have this:

#!/Python27/python.exe

import psycopg2

# Try to connect

conn=psycopg2.connect("dbname='busard_test' user='laurent' host='localhost' password='cactus'")
cur = conn.cursor()


On Fri, May 16, 2014 at 12:41 PM, image <lcelati@latitude-geosystems.com> wrote:
Hello,

Thanks. Ok i deleted the except. Please find below the 2 updates usefull
liles :

pg_test.py
<http://postgresql.1045698.n5.nabble.com/file/n5804203/pg_test.py>

SS_dos.JPG
<http://postgresql.1045698.n5.nabble.com/file/n5804203/SS_dos.JPG>


In advance, thank you.

Regards.

IMAGE.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804203.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: Psycopg2 : error message.

From
Karsten Hilbert
Date:
On Fri, May 16, 2014 at 03:41:15AM -0700, image wrote:

> Thanks. Ok i deleted the except. Please find below the 2 updates usefull
> liles :
>
> pg_test.py
> <http://postgresql.1045698.n5.nabble.com/file/n5804203/pg_test.py>

You need to learn to write proper Python code, especially try: except: blocks.

Your first try: lacks an except: part.

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346


Re: Psycopg2 : error message.

From
image
Date:
Thanks for your help.

So i remove the first "try" + i remove the space before "conn="

Indeed i have a new error message in my DOS interface :

pg_test.py
<http://postgresql.1045698.n5.nabble.com/file/n5804207/pg_test.py>

SS_dos.JPG
<http://postgresql.1045698.n5.nabble.com/file/n5804207/SS_dos.JPG>


In advance, thank you.

IMAGE.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804207.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: Psycopg2 : error message.

From
Dorian Hoxha
Date:
Since I can't understand(french?) the language, what does it mean? Probably wrong authentication(password?). 


On Fri, May 16, 2014 at 1:19 PM, image <lcelati@latitude-geosystems.com> wrote:
Thanks for your help.

So i remove the first "try" + i remove the space before "conn="

Indeed i have a new error message in my DOS interface :

pg_test.py
<http://postgresql.1045698.n5.nabble.com/file/n5804207/pg_test.py>

SS_dos.JPG
<http://postgresql.1045698.n5.nabble.com/file/n5804207/SS_dos.JPG>


In advance, thank you.

IMAGE.




--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804207.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: Psycopg2 : error message.

From
Karsten Hilbert
Date:
On Fri, May 16, 2014 at 04:19:25AM -0700, image wrote:

> Indeed i have a new error message in my DOS interface :
>
> pg_test.py
> <http://postgresql.1045698.n5.nabble.com/file/n5804207/pg_test.py>
>
> SS_dos.JPG
> <http://postgresql.1045698.n5.nabble.com/file/n5804207/SS_dos.JPG>

You'll have to

    - translate the message for us

    - configure PostgreSQL so you have got
      permissions to connect

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346


Re: Psycopg2 : error message.

From
Karsten Hilbert
Date:
You need to search the web for how and whether to quote
values inside the DSN for psycopg2.

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346


Re: Psycopg2 : error message.

From
Adrian Klaver
Date:
On 05/16/2014 04:19 AM, image wrote:
> Thanks for your help.
>
> So i remove the first "try" + i remove the space before "conn="
>
> Indeed i have a new error message in my DOS interface :
>
> pg_test.py
> <http://postgresql.1045698.n5.nabble.com/file/n5804207/pg_test.py>
>
> SS_dos.JPG
> <http://postgresql.1045698.n5.nabble.com/file/n5804207/SS_dos.JPG>
>
>
> In advance, thank you.

In the future this is a question that is more appropriate for the
psycopg2 list:

http://www.postgresql.org/list/psycopg/

You also should take a look at here for some basic pointers:

http://initd.org/psycopg/docs/usage.html

FYI it is not necessary to single quote the parameter values in the
connection string.

Lastly, if my high school French is holding up you have an
authentication error for user laurent. The first thing to check would
whether you  are using the correct password.



>
> IMAGE.
>
>
>
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804207.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Psycopg2 : error message.

From
skeeved
Date:
Looks like you have an invalid connection string:
conn=psycopg2.connect("dbname='busard_test' user='laurent' host='localhost' password='cactus’")
Try removing the double quotes, they are obscuring the parameter names and values:
conn=psycopg2.connect(dbname=‘busard_test', user=‘laurent', host=‘localhost', password='cactus’)
You were also missing some punctuation between the parameters.
-- 
skeeved

On May 16, 2014 at 9:39:06 AM, Adrian Klaver (adrian.klaver@aklaver.com) wrote:

On 05/16/2014 04:19 AM, image wrote:
> Thanks for your help.
>
> So i remove the first "try" + i remove the space before "conn="
>
> Indeed i have a new error message in my DOS interface :
>
> pg_test.py
> <http://postgresql.1045698.n5.nabble.com/file/n5804207/pg_test.py>
>
> SS_dos.JPG
> <http://postgresql.1045698.n5.nabble.com/file/n5804207/SS_dos.JPG>
>
>
> In advance, thank you.

In the future this is a question that is more appropriate for the
psycopg2 list:

http://www.postgresql.org/list/psycopg/

You also should take a look at here for some basic pointers:

http://initd.org/psycopg/docs/usage.html

FYI it is not necessary to single quote the parameter values in the
connection string.

Lastly, if my high school French is holding up you have an
authentication error for user laurent. The first thing to check would
whether you are using the correct password.



>
> IMAGE.
>
>
>
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804207.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: Psycopg2 : error message.

From
Karsten Hilbert
Date:
On Fri, May 16, 2014 at 11:07:42AM -0400, skeeved wrote:

> Looks like you have an invalid connection string:
> conn=psycopg2.connect("dbname='busard_test' user='laurent' host='localhost' password='cactus’")
> Try removing the double quotes, they are obscuring the parameter names and values:
> conn=psycopg2.connect(dbname=‘busard_test', user=‘laurent', host=‘localhost', password='cactus’)
> You were also missing some punctuation between the parameters.

He was using the DSN-as-string variant, not the keyword one.

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346


Re: Psycopg2 : error message.

From
image
Date:
Dear all,

Thank you for your replies.Before taking into account your last proposals, I
would like to tell you : I noticed that i don't get error message when i use
the default user (postgres). But when i use my new user account (laurent), i
get the error message.

With pgadmin3 i would like edit the authorization for the database (recalled
web_service). But when i try to add permissions, i can't click on "ok"
because it's neutralized (grayed").

On the following screen shot (pgadmin), below, we notice the defalut value
(TC) for the 'public' role. Here the role seems to be meaning the windows
account and not the postgres role?

SS_permissions.JPG
<http://postgresql.1045698.n5.nabble.com/file/n5804240/SS_permissions.JPG>

May be i have to do edit something into the pghba.conf in order to authorize
connection for the new role laurent? For information, i'm working under
'laurent' windows session.

Thank you to throw light for me.

Regards.



--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804240.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: Psycopg2 : error message.

From
Adrian Klaver
Date:
On 05/16/2014 08:07 AM, skeeved wrote:
> Looks like you have an invalid connection string:
>
> conn=psycopg2.connect("dbname='busard_test' user='laurent' host='localhost' password='cactus’")
>
> Try removing the double quotes, they are obscuring the parameter names and values:
>
> conn=psycopg2.connect(dbname=‘busard_test', user=‘laurent', host=‘localhost', password='cactus’)
>
> You were also missing some punctuation between the parameters.

See below for the two ways of specifying connection parameters:

http://initd.org/psycopg/docs/module.html#psycopg2.connect

The OPs way is correct, the only thing is the single quotes are redundant.

>
> --
> skeeved
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Psycopg2 : error message.

From
Adrian Klaver
Date:
On 05/16/2014 08:41 AM, image wrote:
> Dear all,
>
> Thank you for your replies.Before taking into account your last proposals, I
> would like to tell you : I noticed that i don't get error message when i use
> the default user (postgres). But when i use my new user account (laurent), i
> get the error message.

Did you set up a password for laurent?

>
> With pgadmin3 i would like edit the authorization for the database (recalled
> web_service). But when i try to add permissions, i can't click on "ok"
> because it's neutralized (grayed").

At a guess you logged in as laurent not as the database superuser
postgres. This assumes laurent is not a superuser. This would explain
why you do not have rights to grant permissions.

>
> On the following screen shot (pgadmin), below, we notice the defalut value
> (TC) for the 'public' role. Here the role seems to be meaning the windows
> account and not the postgres role?

No it would be the Postgres role.

>
> SS_permissions.JPG
> <http://postgresql.1045698.n5.nabble.com/file/n5804240/SS_permissions.JPG>
>
> May be i have to do edit something into the pghba.conf in order to authorize
> connection for the new role laurent? For information, i'm working under
> 'laurent' windows session.

Can you show your pg_hba.conf file?

>
> Thank you to throw light for me.
>
> Regards.
>
>
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804240.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Psycopg2 : error message.

From
Adrian Klaver
Date:
On 05/16/2014 08:41 AM, image wrote:
> Dear all,
>

>
> Thank you to throw light for me.

Hit send to soon. Meant to add that the French version of the manual is
available here:

http://docs.postgresql.fr/9.3/

Might help with some of the basics.

>
> Regards.
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Psycopg2 : error message.

From
image
Date:
Dear all,

Thank you again for your replies.

So regarding my issue with my 'laurent' user account, i remove double quote
and i add punctuation between the parameters. But it's always the same
result. I succeed in connecting to my pg database with the postgres user.

But i have the same problem with 'laurent' user, same error message.  The
problem seems to come from the laurent account.

Below i past my pg_hba.conf. I just add a line allowing all connections
(trust) for anyone user.

pg_hba.sample
<http://postgresql.1045698.n5.nabble.com/file/n5804474/pg_hba.sample>

I tried to re run services . I think that postgres services were down
beacause when i try to run services, a message appears saying :

--------------------------------------
postgresql x64 9.3 service. Postgre sql server has started , then has
stopped. Some services stop automatically when it are not used by other
serices or programs.
--------------------------------------

Do you know the cause of this trouble? this message appears even if the file
is raw, unmodified

I have to edit anything into my pg_hba.conf?



Thanks.





--
View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804474.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: Psycopg2 : error message.

From
Adrian Klaver
Date:
On 05/19/2014 06:17 AM, image wrote:
> Dear all,
>
> Thank you again for your replies.
>
> So regarding my issue with my 'laurent' user account, i remove double quote
> and i add punctuation between the parameters. But it's always the same
> result. I succeed in connecting to my pg database with the postgres user.
>
> But i have the same problem with 'laurent' user, same error message.  The
> problem seems to come from the laurent account.

So what happens when you try to use the command line program psql or
pgAdmin to connect as laurent?

>
> Below i past my pg_hba.conf. I just add a line allowing all connections
> (trust) for anyone user.
>
> pg_hba.sample
> <http://postgresql.1045698.n5.nabble.com/file/n5804474/pg_hba.sample>

That is not the pg_hba.conf file you want. That is the template file
Postgres uses to build a pg_hba.conf when it does an initdb.

>
> I tried to re run services . I think that postgres services were down
> beacause when i try to run services, a message appears saying :
>
> --------------------------------------
> postgresql x64 9.3 service. Postgre sql server has started , then has
> stopped. Some services stop automatically when it are not used by other
> serices or programs.
> --------------------------------------
>
> Do you know the cause of this trouble? this message appears even if the file
> is raw, unmodified

Not sure. You will need to provide more information. Looking in the
Postgres logs would be a good start, as well as the Windows system logs.


>
> I have to edit anything into my pg_hba.conf?

Possibly, though not the pg_hba.conf you show above. pgAdmin should
allow you to edit the correct file.

>
>
>
> Thanks.
>
>
>
>
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/Psycopg2-error-message-tp5804197p5804474.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>
>


--
Adrian Klaver
adrian.klaver@aklaver.com