pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Seeking PyGreSQL help
9+ messages / 2 participants
[nested] [flat]

* Seeking PyGreSQL help
@ 2003-08-05 08:16  Alastair G. Hogge <agh@tpg.com.au>
  0 siblings, 1 reply; 9+ messages in thread

From: Alastair G. Hogge @ 2003-08-05 08:16 UTC (permalink / raw)
  To: pgsql-interfaces

Hello,

I'm running PostgreSQL-7.3.3_1 on FreeBSD 5.0-CURRENT. I'm trying to use 
python to interface with my database. I'm using Python-2.3 and 
py23-PyGreSQL-7.3.3_1 from the FreeBSD ports tree.

My problem is when I try to connect to the database.
Following is how the problem occurs:
<error>
#python
>>>import _pg
>>>db = _pg.connect("mydb", "myhost")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
_pg.error: could not connect to server: Connection refused
        Is the server running on host myhost and accepting
        TCP/IP connections on port 5432?
</erro>

I know my database is working because when I load it up with psql all appears 
ok. I can even add and retrive information.

I'm only just starting out in Python and PostgreSQL so any help would be much 
appreciated.

Thanks in advance
-Al




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-05 09:10  D'Arcy J.M. Cain <darcy@PyGreSQL.org>
  parent: Alastair G. Hogge <agh@tpg.com.au>
  0 siblings, 1 reply; 9+ messages in thread

From: D'Arcy J.M. Cain @ 2003-08-05 09:10 UTC (permalink / raw)
  To: Alastair G. Hogge <agh@tpg.com.au>; pgsql-interfaces

On Tuesday 05 August 2003 04:16, Alastair G. Hogge wrote:
> I'm running PostgreSQL-7.3.3_1 on FreeBSD 5.0-CURRENT. I'm trying to use
> python to interface with my database. I'm using Python-2.3 and
> py23-PyGreSQL-7.3.3_1 from the FreeBSD ports tree.
>
> My problem is when I try to connect to the database.
> Following is how the problem occurs:
> <error>
> #python
>
> >>>import _pg
> >>>db = _pg.connect("mydb", "myhost")
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> _pg.error: could not connect to server: Connection refused
>         Is the server running on host myhost and accepting
>         TCP/IP connections on port 5432?

What happens if you do 'db = _pg.connect("mydb")' from python or 'psql -h 
myhost' from the command line?  I suspect that your problem will reverse.  Bt 
default PostgreSQL does not run on a TCP/IP port.  You have to turn that on 
from the config file.  Don't forget pg_hba.conf if you change that.

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-05 10:09  Alastair G. Hogge <agh@tpg.com.au>
  parent: D'Arcy J.M. Cain <darcy@PyGreSQL.org>
  0 siblings, 2 replies; 9+ messages in thread

From: Alastair G. Hogge @ 2003-08-05 10:09 UTC (permalink / raw)
  To: darcy@PyGreSQL.org; pgsql-interfaces

On Tuesday, 05 August 2003 19:10, D'Arcy J.M. Cain wrote:
> On Tuesday 05 August 2003 04:16, Alastair G. Hogge wrote:
> > I'm running PostgreSQL-7.3.3_1 on FreeBSD 5.0-CURRENT. I'm trying to use
> > python to interface with my database. I'm using Python-2.3 and
> > py23-PyGreSQL-7.3.3_1 from the FreeBSD ports tree.
> >
> > My problem is when I try to connect to the database.
> > Following is how the problem occurs:
> > <error>
> > #python
> >
> > >>>import _pg
> > >>>db = _pg.connect("mydb", "myhost")
> >
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > _pg.error: could not connect to server: Connection refused
> >         Is the server running on host myhost and accepting
> >         TCP/IP connections on port 5432?
>
> What happens if you do 'db = _pg.connect("mydb")' from python or 'psql -h
> myhost' from the command line?  I suspect that your problem will reverse. 
> Bt default PostgreSQL does not run on a TCP/IP port.  You have to turn that
> on from the config file.  Don't forget pg_hba.conf if you change that.
Hello Darcy,

Thanks for help. The problem was in pgsql/data/postgresql.conf. I needed to 
change "#tcpip_socket = false" to "tcpip_socket = true"
I know am able to access my database from within Python, hwover when I try the 
python an cgi script I get an internet server error. Is there more options I 
should know about?






^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-05 12:41  Alastair G. Hogge <agh@tpg.com.au>
  parent: Alastair G. Hogge <agh@tpg.com.au>
  1 sibling, 1 reply; 9+ messages in thread

From: Alastair G. Hogge @ 2003-08-05 12:41 UTC (permalink / raw)
  To: darcy@PyGreSQL.org; pgsql-interfaces

On Tuesday, 05 August 2003 20:09, Alastair G. Hogge wrote:
OK, I've found my problem.
my code:
form = cgi.FieldStorage() # Grab data from web page form
db = _pg.connect("mydb", "myhost") # connect to database
temp = form['name'].value
db.query("INSERT INTO test VALUES (temp, 'none')")
db.close()

The following is to show that data has been recived from the web form.
Which works. temp will display what ever I type in the form, however, when I 
try to store it in the database above I get problems.
print "Content-Type: text/html\n\n"
print temp 

"db.query("INSERT INTO test VALUES (temp, 'none')")" is the line causing the 
problem. The internel server error from apache.




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-05 12:42  D'Arcy J.M. Cain <darcy@PyGreSQL.org>
  parent: Alastair G. Hogge <agh@tpg.com.au>
  1 sibling, 0 replies; 9+ messages in thread

From: D'Arcy J.M. Cain @ 2003-08-05 12:42 UTC (permalink / raw)
  To: Alastair G. Hogge <agh@tpg.com.au>; pgsql-interfaces

On Tuesday 05 August 2003 06:09, Alastair G. Hogge wrote:
> Thanks for help. The problem was in pgsql/data/postgresql.conf. I needed to
> change "#tcpip_socket = false" to "tcpip_socket = true"
> I know am able to access my database from within Python, hwover when I try
> the python an cgi script I get an internet server error. Is there more
> options I should know about?

I assume that you mean "Internal Server Error" or ISE.  Whenever your web 
server gives an ISE there is something in the error log that tells you what 
the problem is.  With Python you will get the exact line with the problem.  
From there it is simpy a matter of debugging your code.

If you can't get access to the error logs for whatever reason you can add the 
following line to your Python script to see the error in your browser.

import sys
sys.stderr = sys.stdout

You may have to view the source to see the error properly as your browser will 
try to "format" it for you.

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-05 12:45  D'Arcy J.M. Cain <darcy@PyGreSQL.org>
  parent: Alastair G. Hogge <agh@tpg.com.au>
  0 siblings, 1 reply; 9+ messages in thread

From: D'Arcy J.M. Cain @ 2003-08-05 12:45 UTC (permalink / raw)
  To: Alastair G. Hogge <agh@tpg.com.au>; pgsql-interfaces

On Tuesday 05 August 2003 08:41, Alastair G. Hogge wrote:
> "db.query("INSERT INTO test VALUES (temp, 'none')")" is the line causing
> the problem. The internel server error from apache.

What happens when you try doing that line directly into psql?  I don't know 
what your schema for test is but perhaps what you want is this:

db.query("INSERT INTO test VALUES (temp, NULL)")

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-05 12:53  Alastair G. Hogge <agh@tpg.com.au>
  parent: D'Arcy J.M. Cain <darcy@PyGreSQL.org>
  0 siblings, 1 reply; 9+ messages in thread

From: Alastair G. Hogge @ 2003-08-05 12:53 UTC (permalink / raw)
  To: darcy@PyGreSQL.org; pgsql-interfaces

On Tuesday, 05 August 2003 22:45, D'Arcy J.M. Cain wrote:
> On Tuesday 05 August 2003 08:41, Alastair G. Hogge wrote:
> > "db.query("INSERT INTO test VALUES (temp, 'none')")" is the line causing
> > the problem. The internel server error from apache.
>
> What happens when you try doing that line directly into psql?  I don't know
> what your schema for test is but perhaps what you want is this:
>
> db.query("INSERT INTO test VALUES (temp, NULL)")
In pyhton?
temp = "hello"
>>> db.query("INSERT INTO test VALUES (temp, NULL)")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
_pg.error: ERROR:  Attribute "temp" not found




^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-05 16:44  D'Arcy J.M. Cain <darcy@PyGreSQL.org>
  parent: Alastair G. Hogge <agh@tpg.com.au>
  0 siblings, 1 reply; 9+ messages in thread

From: D'Arcy J.M. Cain @ 2003-08-05 16:44 UTC (permalink / raw)
  To: Alastair G. Hogge <agh@tpg.com.au>; pgsql-interfaces

On Tuesday 05 August 2003 08:53, Alastair G. Hogge wrote:
> In pyhton?
> temp = "hello"
>
> >>> db.query("INSERT INTO test VALUES (temp, NULL)")
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> _pg.error: ERROR:  Attribute "temp" not found

Right.  That's the error.  You are trying to pass a Python variable name to 
the PostgreSQL backend.  Go to the Python page and look up formatting with 
the '%' operator.

-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org



^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: Seeking PyGreSQL help
@ 2003-08-06 01:23  Alastair G. Hogge <agh@tpg.com.au>
  parent: D'Arcy J.M. Cain <darcy@PyGreSQL.org>
  0 siblings, 0 replies; 9+ messages in thread

From: Alastair G. Hogge @ 2003-08-06 01:23 UTC (permalink / raw)
  To: darcy@PyGreSQL.org; pgsql-interfaces

On Wednesday, 06 August 2003 02:44, D'Arcy J.M. Cain wrote:
> On Tuesday 05 August 2003 08:53, Alastair G. Hogge wrote:
> > In pyhton?
> > temp = "hello"
> >
> > >>> db.query("INSERT INTO test VALUES (temp, NULL)")
> >
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > _pg.error: ERROR:  Attribute "temp" not found
>
> Right.  That's the error.  You are trying to pass a Python variable name to
> the PostgreSQL backend.  Go to the Python page and look up formatting with
> the '%' operator.
Ah I see. Thanks for that.
All is working ok now. :-)
-Al






^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2003-08-06 01:23 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-05 08:16 Seeking PyGreSQL help Alastair G. Hogge <agh@tpg.com.au>
2003-08-05 09:10 ` D'Arcy J.M. Cain <darcy@PyGreSQL.org>
2003-08-05 10:09   ` Alastair G. Hogge <agh@tpg.com.au>
2003-08-05 12:41     ` Alastair G. Hogge <agh@tpg.com.au>
2003-08-05 12:45       ` D'Arcy J.M. Cain <darcy@PyGreSQL.org>
2003-08-05 12:53         ` Alastair G. Hogge <agh@tpg.com.au>
2003-08-05 16:44           ` D'Arcy J.M. Cain <darcy@PyGreSQL.org>
2003-08-06 01:23             ` Alastair G. Hogge <agh@tpg.com.au>
2003-08-05 12:42     ` D'Arcy J.M. Cain <darcy@PyGreSQL.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox