username containing hyphens with psycopg2 running under Anaconda

206 views Asked by At

I have a postgres username that contains a hyphen (example: 'user-1'). The following code works with python 2.6.3, but not with Python 2.7.10 :: Anaconda 1.9.2 (64-bit). I tried both single and double quotes around the username. Any ideas?

username = 'user-1'
try:
    con = psycopg2.connect(
            database = database,
            user = username,
            password = password,
            host = hostname
        )
except:
    print "I am unable to connect to the database."

The code errors with:

"/usr/local/apps/python/anaconda-current/lib/python2.7/site-packages/psycopg2/i‌​nit.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) psycopg2.OperationalError: FATAL: password authentication failed for user "user-1

0

There are 0 answers