On Thu, 13 May 2010 09:25:21 -0400, Michael Bayer <mike...@zzzcomputing.com> wrote: > > On May 13, 2010, at 7:33 AM, Faheem Mitha wrote: > >> >> Hi, >> >> In >> >> http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/connections.html#creating-engines >> >> it describes how permitted urls are of the form >> >> dialect://user:passw...@host/dbname[?key=value..], >> >> I'm using postgresql. I believe sqlalchemy uses psycopg2 by default. >> >> I've been connecting using psycopg2 via unix socket and ident sameuser, This >> does not require either host or password. psycopg2 allows me to leave both >> host and password empty. I tested and sqlalchemy barfs if even the password >> is not supplied. If I want to use sqlalchemy, what are my options? > > > Simply don't put a colon: > > from sqlalchemy import * > > e = create_engine('postgresql://sc...@localhost/test', echo=True) > e.connect()
Not sure which colon you mean. I wasn't using a colon after the username. Ok, so this works - just leaving out password with the colon before it, and leaving out localhost (but leaving in the colon after it). Phew. usr = "faheem" db = "template1" dbstring = "postgres://%s@:5432/%s"%(usr, db) username = "foo" print dbuser_exists(dbstring, username) In case anyone is curious, the function is def dbuser_exists(dbstring, username): from sqlalchemy import create_engine db = create_engine(dbstring) conn = db.connect() from sqlalchemy.sql import text q = text("""select usename from pg_user where usename = '%s';"""%username) result = conn.execute(q).fetchall() conn.close() if len(result) > 0 and result[0][0]==username: return True else: return False Regards, Faheem. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.