473,761 Members | 5,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

psycopg authentication

Hello, I'm new to both PostgreSQL and psycopg and I'm trying to connect
to my database running on localhost. I have postgres setup to do md5
authentication and this works when using a db admin tool on my local
network. For some reason, psycopg fails with IDENT authentication.
import psycopg
psycopg.connect ("dbname=jlower y user=jlowery host=localhost

password=XXX")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
psycopg.Operati onalError: FATAL 1: IDENT authentication failed for
user "jlowery"

Is there a way to make this module connect with MD5 auth?

Jul 18 '05 #1
7 8011
On 2005-03-12, js******@gmail. com <js******@gmail .com> wrote:
Hello, I'm new to both PostgreSQL and psycopg and I'm trying to connect
to my database running on localhost. I have postgres setup to do md5
authentication and this works when using a db admin tool on my local
network. For some reason, psycopg fails with IDENT authentication.
import psycopg
psycopg.connect ("dbname=jlower y user=jlowery host=localhost

password=XXX")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
psycopg.Operati onalError: FATAL 1: IDENT authentication failed for
user "jlowery"

Is there a way to make this module connect with MD5 auth?

Are you sure you do not have local connections set up
for md5 and host authentications still set to ident?

Did you restart the server after updating pg_hba.conf?
Jul 18 '05 #2
I did, the pg_hba conf is a big tricky to me. I've tried the following
things.. the commented out lines I also tried.

#local all ident
sameuser
local all md5
host all 127.0.0.1 255.0.0.0 ident
sameuser
#host all 127.0.0.1 255.255.255.255 md5
host all 0.0.0.0 0.0.0.0 md5

I have an admin program "EMS PostgreSQL Manager" on my lan and it
connects fine with my user name and password.

Jul 18 '05 #3
Thanks for the reply. I figured it out, the problem was with my
postgresql configuration. the following seemed to do the trick.

local all
md5
host all 0.0.0.0 0.0.0.0 md5

Jul 18 '05 #4
I'm rebuilding my old library i've done some year ago using python and
postgres.

My problem is to do a middle layer over pycopg for eliminate type
casting problem in postgres in all direction.

i've resolved this doing a C extension in python and manipulating only
string and int in my application.

this is my example:
import sqlvar

sql = """insert into mytable (myint, mytext, maydate)
values
(%d,%s,%s);""" % (sqlvar.number( myvalue1),
sqlvar.text(myv alue2), sqlvar.date(myv alue3) )

all problem concerning quoting, " ' -> ''", null, None, 0, empty string
is solved by the sqlvar lib.
I want to eliminate this problem forever, i want to manipulate only
correct type as DateTime obj in my application so i want to arrive at
this solution:
sql = """insert into mytable (myint, mytext, maydate)
values
(%s,%s,%s);""" % (myvalue1, myvalue2, myvalue3)

without all time check for none, empty string and so on...

I've seen API of psycopg and some procedure for the solution but all are
too spaghetti for me.

I'm only with this problem ?
Glauco
--

\\\|///
\\ - - //
( @ @ )
+---------------------oOOo-( )-oOOo--------------------------+
| |
| I have a dream that one day this nation will rise up and |
| live out the true meaning of its creed: "We hold these |
| truths to be self-evident:that all men are created equal.|
| I have a dream that one day on the red hills of Georgia |
| the sons of former slaves and the sons of former |
| slaveowners will be able to sit down together at a table |
| of brotherhood. |
| I have a dream that one day even the state of Mississippi, |
| a desert state, sweltering with the heat of injustice |
| and oppression, will be transformed into an oasis of |
| freedom and justice. |
| I have a dream that my four children will one day live in |
| a nation where they will not be judged by the color of |
| their skin but by the content of their character. |
| I have a dream today. |
| |
| Martin Luther King, Jr 28 Ago 1963 |
+------------------------------------------------------------+
| glauco(at)urila nd.it |
| www.uriland.it .oooO ICQ: 115323690 |
+--------------------- ( )------ Oooo.---------------------+
\ ( ( )
\_) ) /
(_/
Jul 21 '05 #5
On Fri, Jul 08, 2005 at 04:23:50PM +0200, Glauco wrote:
[...]
My problem is to do a middle layer over pycopg for eliminate type
casting problem in postgres in all direction.

i've resolved this doing a C extension in python and manipulating only
string and int in my application.

this is my example:
import sqlvar

sql = """insert into mytable (myint, mytext, maydate)
values
(%d,%s,%s);""" % (sqlvar.number( myvalue1),
sqlvar.text(myv alue2), sqlvar.date(myv alue3) )

all problem concerning quoting, " ' -> ''", null, None, 0, empty string
is solved by the sqlvar lib. [...]


Instead of quoting Python values yourself appropriately for each type,
just let the DB-API module do its work. Use parametrized queries and
then supply the arguments to the query:

cur = con.cursor()
intVal = 42
textVal = "Jason's house"
dateVal = datetime.date(2 005, 7, 8)
cur.execute("""
insert into mytable(myint, mytext, mydate)
values (%s, %s, %s)
""", (intval, textVal, dateVal))

The execute(many) method has an optional second parameter, which is a
tuple of values for your parametrized query.

There are different styles to parametrize queries among the various
DB-API modules. psycopg uses the pyformat one, where you just use %s as
placeholders.

It will happily quote all Python values of types int, str, date, float,
etc. for you. It's also possible to teach it how to quote other custom
data types, but you'll normally not need this.

HTH,

-- Gerhard
--
Gerhard Häring - gh@ghaering.de - Python, web & database development

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCzo7KdIO 4ozGCH14RAtnmAJ 9F1UB3AWyiUwjw8 D52kRbYOmIRCQCf d8IL
lbqe8geaR6RfDP3 pCrq3Bxg=
=2iQo
-----END PGP SIGNATURE-----

Jul 21 '05 #6
Gerhard Haering wrote:
On Fri, Jul 08, 2005 at 04:23:50PM +0200, Glauco wrote:
[...]
My problem is to do a middle layer over pycopg for eliminate type
casting problem in postgres in all direction.

i've resolved this doing a C extension in python and manipulating only
string and int in my application.

this is my example:
import sqlvar

sql = """insert into mytable (myint, mytext, maydate)
values
(%d,%s,%s);""" % (sqlvar.number( myvalue1),
sqlvar.text(m yvalue2), sqlvar.date(myv alue3) )

all problem concerning quoting, " ' -> ''", null, None, 0, empty string
is solved by the sqlvar lib. [...]

Instead of quoting Python values yourself appropriately for each type,
just let the DB-API module do its work. Use parametrized queries and
then supply the arguments to the query:

cur = con.cursor()
intVal = 42
textVal = "Jason's house"
dateVal = datetime.date(2 005, 7, 8)
cur.execute("""
insert into mytable(myint, mytext, mydate)
values (%s, %s, %s)
""", (intval, textVal, dateVal))

The execute(many) method has an optional second parameter, which is a
tuple of values for your parametrized query.

There are different styles to parametrize queries among the various
DB-API modules. psycopg uses the pyformat one, where you just use %s as
placeholders.

It will happily quote all Python values of types int, str, date, float,
etc. for you. It's also possible to teach it how to quote other custom
data types, but you'll normally not need this.

HTH,

-- Gerhard


Gerhard thank you very much, this example explain me some idea, but
anyway don't resolve the core question.
In you example when dateVal is a None or textVal is none.
argument x must be DateTime, not None.
so i must manipulate for the empty string or None cases

Glauco
--
Jul 21 '05 #7
Glauco wrote:
[...]
Gerhard thank you very much, this example explain me some idea, but
anyway don't resolve the core question.
In you example when dateVal is a None or textVal is none.
argument x must be DateTime, not None.
so i must manipulate for the empty string or None cases


No, you don't. If you leverage the two-parameter form of .execute(many),
your Python DB-API module will handle the None => NULL case for you
transparently.

-- Gerhard
Jul 21 '05 #8

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

Similar topics

1
1476
by: Jim Hefferon | last post by:
Hello, I want to try psycopg, the module for Postgres access. I'm having trouble reaching the site for four or five days now. For example, the link on the Python web site's DB Modules page http://initd.org/Software/psycopg times out, as do some other links that Google gives me. Am I looking in the wrong place, or is it just that the site is experiencing some difficulties? Thanks, Jim
8
2142
by: Alban Hertroys | last post by:
Hello, I'm using psycopg to insert records in a number of threads. After the threads finish, another thread runs to collect the inserted data. Now, my problem is that psycopg let's my threads end before the inserts actually took place, resulting in my collecting thread finding no records... They are inserted after it checks. Is there a way to tell psycopg or python to wait until the insert took place?
12
2623
by: Alban Hertroys | last post by:
Good day, I have a number of threads doing inserts in a table, after which I want to do a select. This means that it will occur that the row that I want to select is locked (by the DB). In these cases, I believe I receive an OperationalError (or is it an InterfaceError?). Is it possible (and if so - how?) to verify that the exception occured because of row locking, so that I can wait and try again?
4
6400
by: Alban Hertroys | last post by:
Another python/psycopg question, for which the solution is probably quite simple; I just don't know where to look. I have a query that inserts data originating from an utf-8 encoded XML file. And guess what, it contains utf-8 encoded characters... Now my problem is that psycopg will only accept queries of type str, so how do I get my utf-8 encoded data into the DB? I can't do query.encode('ascii'), that would be similar to: >>> x =...
11
9025
by: Alban Hertroys | last post by:
Oh no! It's me and transactions again :) I'm not really sure whether this is a limitation of psycopg or postgresql. When I use multiple cursors in a transaction, the records inserted at the start of the transaction aren't visible to those later on in that transaction (using a different cursor). Attached is a simplified example (the except's are a bit blunt, I know) of what I'm trying to do. In reality, the different cursors are...
1
1550
by: roderik | last post by:
How do I supress the output generated from each psycopg command: >>> import psycopg initpsycopg: initializing psycopg 1.99.10 typecast_init: initializing NUMBER .. .. microprotocols_add: cast 0x46dd20 for (bool, ?) initpsycopg: module initialization complete
1
1900
by: Eino Mäkitalo | last post by:
I had Visual C++ 6.0, so I compiled those libpq.dll and psycopg.pyd. if there are anyone to play with Windows, Python 2.3 and Postgre-8.0.0-beta4 for windows like me. You cat get those from: http://eino.net/html/python.html Original psycopg source code is available in: http://initd.org/projects/psycopg1
4
3231
by: Michele Simionato | last post by:
Look at this example: >>> import psycopg >>> psycopg.__version__ '1.1.19' >>> import datetime >>> today = datetime.datetime.today() >>> co = psycopg.connect('') >>> cu = co.cursor()
2
4368
by: Martin P. Hellwig | last post by:
Hi all, I'm playing a bit with PostgreSQL, in which I've set me the target to create a python script which with user input creates a new user role and a database with that owner (connecting to template1 since I know that at least that db exists). Ok so I installed PostGreSQL and pygresql since it looked like that this is endorsed by PG, I had some trouble with the DB-API2 (complains about there is already a connection to template1,...
0
9522
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10111
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.