Re: Psycopg2 : error message.

2014-05-19 Thread Tim Roberts
dandrigo  wrote:
>
>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. 

Really, this wouldn't have been so hard to figure out if you had read the
documentation.

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

Psycopg2 has two ways to specify the parameters.  You can either do them as
individual Python parameters, in which case each parameter is a string that
needs to be quited, OR you can use a single connection string, in which
case you do NOT quote the individual parameters.

So, you can either do this:

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

or do this:

 conn=psycopg2.connect(database='busard_test', user='laurent',
host='localhost', password='cactus'")
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Psycopg2 : error message.

2014-05-16 Thread Chris Angelico
On Fri, May 16, 2014 at 8:18 PM, dandrigo  wrote:
> Please read the 2 usefull files below :
>
> Dandrigo pg_test.py 
>
> SS_dos.JPG 

These would be MUCH better included inline. Please, in future, copy
and paste the *text* of the error message - don't post a screenshot.

As to the actual problem: You're masking a potentially useful
exception behind a bare except that just prints a generic message *and
then continues*. This is a very bad idea. Don't do it. Take all that
out and just attempt the connection; then you'll get a useful error.
Same further down. Just don't.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list