SQLALCHEMY_DATABASE_URI with psycopg2 wont work if password have '+'

Issue #3077 duplicate
Marcin Jabrzyk created an issue

Just tried to create URI connection string where user have password with '+' character, SQLAlchemy gives no clue in error and connecting to database using psql works fine. Example URI: SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://user:user+@somehosy.somedomain.com:5432/some_db"

Output: sqlalchemy.exc.OperationalError: (OperationalError) FATAL: password authentication failed for user "user" FATAL: password authentication failed for user "user" None None

Changing password to not having '+' works fine.

Comments (4)

  1. Mike Bayer repo owner

    see http://docs.sqlalchemy.org/en/rel_0_9/changelog/migration_09.html#the-password-portion-of-a-create-engine-no-longer-considers-the-sign-as-an-encoded-space . In 0.9, this script passes:

    from sqlalchemy.engine import url
    
    for pw in (
                "postgresql+psycopg2://user:user+@somehosy.somedomain.com:5432/some_db",
                "postgresql+psycopg2://user:user%2B@somehosy.somedomain.com:5432/some_db"
            ):
    
        u = url.make_url(pw)
        assert u.password == "user+", u.password
    

    so in 0.8 for a workaround, use the %2B form.

  2. Log in to comment