473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

pgdb connection string

Hello group,

I've run into a small problem with pgdb which is actually not PostgreSQL
specific - I just do not understand the Python syntax at one point.

I'm trying to initialize a connection to a PG database. So help(pgdb) says:

pgdb.connect(connect_string) -connection
connect_string = 'host:database:user:password:opt:tty'
All parts are optional. You may also pass host through
password as keyword arguments. To pass a port, pass it in
the host keyword parameter:
pgdb.connect(host='localhost:5432')

Now from what I understand is that it accepts a string in the form:

"%s:%s:%s:%s" % (conf["db"]["hostname"],
conf["db"]["database"],
conf["db"]["username"],
conf["db"]["password"])

Which actually works. But if I want to pass the port, there's one more
colon and it parses garbage. So what exactly is this host="foobar"
syntax all about? What exactly is passed to pgdb.connect (because it
does not seem to be a string) - is it a dictionary or something?

I'm puzzled.

Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electronics <47***********************@news.freenet.de>
Jun 27 '08 #1
1 3116
Mel
Johannes Bauer wrote:
I'm trying to initialize a connection to a PG database. So help(pgdb)
says:

pgdb.connect(connect_string) -connection
connect_string = 'host:database:user:password:opt:tty'
All parts are optional. You may also pass host through
password as keyword arguments. To pass a port, pass it in
the host keyword parameter:
pgdb.connect(host='localhost:5432')

Now from what I understand is that it accepts a string in the form:

"%s:%s:%s:%s" % (conf["db"]["hostname"],
conf["db"]["database"],
conf["db"]["username"],
conf["db"]["password"])

Which actually works. But if I want to pass the port, there's one more
colon and it parses garbage. So what exactly is this host="foobar"
syntax all about? What exactly is passed to pgdb.connect (because it
does not seem to be a string) - is it a dictionary or something?
My guess is that pgdb.conf is passed a bunch of things, as though its
signature were

def pgdb (connect_string, host=None, database=None, user=None,
password=None):

or something similar. My instinct would be to try

pgdb.connect (':my_database:my_username:my_password', host='localhost:5432')
In my own code, I almost always use a DB-API 2.0 interface and a dict:

db_params = {'database':'my_db', 'host':'dbserver', 'password':"don't tell"}
db = psycopg2.connect (**db_params)

(untested code above) The dict usually gets patched up from environment
variables and command-line arguments before the connect call.

Cheers, Mel.

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roman Suzi | last post by:
Happy New Year to all Pythoneers! I am playing with pysqlite and pgdb and their DB-API conformancy. It was quite interesting to know: - sqlite doesn't have mandatory helper-functions Date,...
1
by: Ram | last post by:
Dear All I am very new to python . i would appreciate any help from you all on this problem which i am facing. I am trying to connect to postgres from python.for this i am using something like...
0
by: James Saker | last post by:
Just curious if anyone's aware of a good recipe for setting up SSL access to postgresql for pgdb (or another appropriate db-sig 2 compliant module). Or any good recommendations/considerations e.g....
14
by: Manuel Tejada | last post by:
Hi My box: RedHat 9.0, Pentium III Recently I upgraded from PostgreSQL 7.3.2 to PostgreSQL 7.4.1. The PostgreSQL 7.3.2's rpms were installed from RehHat CDs The PostgreSQL 7.4.1's rpms I used...
1
by: ekzept | last post by:
the module PGDB which gives Python access to PostgreSql currently wants for a copy of a properly located or proper libpq.dll library, on Windows. anyone know what the current story on this is? ...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
3
by: SteveD | last post by:
Hi guys, http://luaforge.net/frs/?group_id=327 pgdb.zip is an addition to scite-debug, which adds source debugging to the popular SciTE programmer's editor. gdbpy.zip is a standalone version...
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.