I am using Django 1.9.2 and psyopg2 2.6.1 with Python 3.5.0 in a project that I created using http://cookiecutter-django.readthedocs.org/en/latest/ . I have a database configuration that looks like this:
import environ from django.utils.http import urlquote env = environ.Env() DATABASES = { # 1) This does not work. # 'default': env.db("DATABASE_URL", # default="postgres://myuser:% s@127.0.0.1 :5432/mydb" % "1234#abc") # 2) This does not work. # 'default': env.db("DATABASE_URL", # default="postgres://myuser:% s@127.0.0.1 :5432/mydb" % urlquote("1234#abc")) # 3) This works 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mydb', 'USER': 'myuser', 'PASSWORD': '1234#abc', 'PORT': 5432, 'HOST': '127.0.0.1' } }
My database password has # . I can successfully connect to option number 3, but with the other two I get the following errors:
1) ValueError: invalid literal for int() with base 10: '1234'
2) django.db.utils.OperationalError: FATAL: password authentication failed for user "myuser" .
How to send this c # password correctly in PostgreSQL?
duffn source share