PostgreSQL error "unable to connect to server - python

I start learning Django, and I had a problem using the Postegres database,
The server worked fine with sqlite3, but as soon as I declared Postgres in the project, the server stopped working
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql', # on utilise l'adaptateur postgresql
'NAME': 'sarah disquaires', # le nom de notre base de donnees creee precedemment
'USER': 'sarra', # attention : remplacez par votre nom d'utilisateur
'PASSWORD': '',
'HOST': '',
'PORT': '5432',
}
}
I get this error:
python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\postgresql\base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: fe_sendauth: no password supplied
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check_migrations()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\management\base.py", line 486, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\loader.py", line 53, in __init__
self.build_graph()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\loader.py", line 220, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\recorder.py", line 77, in applied_migrations
if self.has_table():
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\migrations\recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
return self._cursor()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
self.ensure_connection()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\backends\postgresql\base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\sarra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: fe_sendauth: no password supplied
I tried to migrate the base with python manage.py makemigrations and python manage.py migrate but didn't work,
I tested several solutions proposed on several sites, but did not work for me.
please help me solve this problem

As the error message says:
no password supplied
So add the database password to the configurarion dictionary and re-run the migration

Related

Django: unknown database name

I am trying to change the database in django from sqlite3 to mysql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER':'myusername',
'PASSWORD':'mypassword',
'HOST':'127.0.0.1',
'PORT':'3306',
}
}
and after trying to run my server i get this error
System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 244, in ensure_connection
self.connect()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 244, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\__init__.py", line 123, in Connect
return Connection(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\connections.py", line 185, in __init__
super().__init__(*args, **kwargs2)
MySQLdb.OperationalError: (1049, "Unknown database 'django'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\commands\runserver.py", line 137, in inner_run
self.check_migrations()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\base.py", line 576, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\loader.py", line 58, in __init__
self.build_graph()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\recorder.py", line 81, in applied_migrations
if self.has_table():
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 284, in cursor
return self._cursor()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 260, in _cursor
self.ensure_connection()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 244, in ensure_connection
self.connect()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 244, in ensure_connection
self.connect()
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\mysql\base.py", line 244, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\__init__.py", line 123, in Connect
return Connection(*args, **kwargs)
File "C:\Users\ыв\AppData\Local\Programs\Python\Python39\lib\site-packages\MySQLdb\connections.py", line 185, in __init__
super().__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1049, "Unknown database 'django'")
i dont know why django can't see my db, maybe you guys have some ideas.
Mysql didn't get me any problems before this case,
i haven't found a way to fix an error, so I counting on your help.
thanks in advance
The shortest answer to that is that django database ist't crated in MySQL. Django will not create the database for you like it do on sqlite3, you have to had this database created before.
You can ensure that you created the database by running a command like that:
$ mysql -h 127.0.0.1 -pmypassword -u myusername # to connect on your mysql
mysql> show databases; # list all databases on your MySQL server
To create a new database my recomendation is the following:
mysql> create database django charset utf8mb4; -- charset is optional
mysql> use django;

Pycharm / Django defer Oracle Database connection

I have a Django project that connects to an Oracle database - implemented in PyCharm. I would like the app to monitor the connection and display a status as to whether the database is up or down. I stopped the listener to simulate an error. However, when I start the PyCharm server to test the functionality, the app immediately attempts a database connection and fails. Is it possible to defer the database connection until I can command one within the app?
Here is the error traceback on server startup:
C:\Users\steve\PycharmProjects\Tools\venv\Scripts\python.exe C:/Users/steve/PycharmProjects/Tools/Tools/manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\oracle\base.py", line 229, in get_new_connection
return Database.connect(
cx_Oracle.DatabaseError: ORA-12541: TNS:no listener
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\steve\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Users\steve\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
self.check_migrations()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\core\management\base.py", line 486, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\migrations\executor.py", line 18, in init
self.loader = MigrationLoader(self.connection)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\migrations\loader.py", line 53, in init
self.build_graph()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\migrations\loader.py", line 220, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\migrations\recorder.py", line 77, in applied_migrations
if self.has_table():
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\migrations\recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
return self._cursor()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
self.ensure_connection()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\steve\PycharmProjects\Tools\venv\lib\site-packages\django\db\backends\oracle\base.py", line 229, in get_new_connection
return Database.connect(
django.db.utils.DatabaseError: ORA-12541: TNS:no listener

Migration error(django.db.utils.OperationalError)

I'm trying to migrate my custom user model and I run makemigrations command to make migrations for new models. But when I run migrate command it throws this error :
conn = _connect(dsn, connection_factory=connection_factory,
**kwasync) django.db.utils.OperationalError
Trace back:
(venv_ruling) C:\Users\enosh\venv_ruling\ruling>python manage.py migrate
Traceback (most recent call last):
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\postgresql\base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\enosh\venv_ruling\lib\site-packages\psycopg2\__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\enosh\venv_ruling\ruling\manage.py", line 22, in <module>
main()
File "C:\Users\enosh\venv_ruling\ruling\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\commands\migrate.py", line 75, in handle
self.check(databases=[database])
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\management\base.py", line 419, in check
all_issues = checks.run_checks(
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\checks\registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\core\checks\model_checks.py", line 34, in check_all_models
errors.extend(model.check(**kwargs))
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\models\base.py", line 1290, in check
*cls._check_indexes(databases),
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\models\base.py", line 1680, in _check_indexes
connection.features.supports_covering_indexes or
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\postgresql\features.py", line 93, in is_postgresql_11
return self.connection.pg_version >= 110000
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\postgresql\base.py", line 329, in pg_version
with self.temporary_connection():
File "C:\Users\enosh\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 117, in __enter__
return next(self.gen)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 603, in temporary_connection
with self.cursor() as cursor:
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
return self._cursor()
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
self.ensure_connection()
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\enosh\venv_ruling\lib\site-packages\django\db\backends\postgresql\base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\enosh\venv_ruling\lib\site-packages\psycopg2\__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError
models.py
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
"""extend usermodel"""
class Meta:
verbose_name_plural = 'CustomUser'
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'rulings',
'USER': 'xxxxxxx',
'PASSWORD': 'xxxxxxx',
'HOST': '',
'PORT': '',
}
}
AUTH_USER_MODEL = 'accounts.CustomUser'
The postgresql's database is empty.(ver.12.6)
I just mentioned user model and settings in this question but still if more code is required then tell me I'll update my question with that information. Thank you
I don't know if you have left the port empty for the question or it is actually empty, but try this in the console and see if the connection is successful.
conn=psycopg2.connect(database="rulings", user="xxx", password="xxx",port=5432)
Also this might not be your port(it is the default but yours might be changed) check your port number \conninfo in the postgres shell. And let me know if it helps.
You have to check for the host_ip or the port number in the settings.py file of django.

Access Denied Django : (1045, "Access denied for user 'darth_vader'#'151.33.241.48' (using password: YES)")

I am using django 3.0 and using MySQL database for my web application.
My settings.py code is:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'thirdihrms',
'USERNAME': 'admin',
'PASSWORD': 'xxxxxxxx',
'HOST': 'database-1.xxxxxxxxx.us-east-1.rds.amazonaws.com',
'PORT': '3306',
}
}
And instead of connecting to the admin#151.33.241.48 it's getting connected to the darth_vader username.
The darth_vader name is my ubantu machine (Local development environment) home user name.
I see "darth_vader#Rushikesh-HP:~$ " when i open my terminal.
The error message:
Traceback (most recent call last):
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
self.connect()
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
return Database.connect(**conn_params)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'darth_vader'#'157.33.241.48' (using password: YES)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 366, in execute
self.check()
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 395, in check
include_deployment_checks=include_deployment_checks,
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 63, in _run_checks
issues = run_checks(tags=[Tags.database])
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/core/checks/database.py", line 10, in check_database_backends
issues.extend(conn.validation.check(**kwargs))
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql/validation.py", line 9, in check
issues.extend(self._check_sql_mode(**kwargs))
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql/validation.py", line 13, in _check_sql_mode
with self.connection.cursor() as cursor:
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 260, in cursor
return self._cursor()
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 236, in _cursor
self.ensure_connection()
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
self.connect()
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
self.connect()
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
return Database.connect(**conn_params)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
return Connection(*args, **kwargs)
File "/home/darth_vader/anaconda3/lib/python3.7/site-packages/MySQLdb/connections.py", line 179, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1045, "Access denied for user 'darth_vader'#'157.33.241.48' (using password: YES)")
So is there any config change or setting change so i can run my application.
The key to specify the username is 'USER' [Django-doc], not 'USERNAME'. As the documentation specifies:
USER
Default: '' (Empty string)
The username to use when connecting to the database. Not used with
SQLite.
You thus should fix this with:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'thirdihrms',
'USER': 'admin', # no USERNAME
'PASSWORD': 'xxxxxxxx',
'HOST': 'database-1.xxxxxxxxx.us-east-1.rds.amazonaws.com',
'PORT': '3306',
}
}

Handling sensitive keys django

OS: Win 8.1
System: surface pro 3
python 2.7.9
postgre: 9.3
django 1.7.1
I am trying to complete the Ultimate Django tutorial: https://ultimatedjango.com/learn-django/lessons/handling-sensitive-keys/?trim=yes
On the section of sensitive keys it gives me the following errors when I run the server with : python manage.py runserver
CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.
Then on the settings.py i put :
ALLOWED_HOSTS = ['*']
and when I run the server again gives the following error:
Performing system checks...
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at
0x00000000035BD588
>
Traceback (most recent call last):
File "c:\venv\lib\site-packages\django\utils\autoreload.py", line 222, in
wrapper
fn(*args, **kwargs)
File "c:\venv\lib\site-
packages\django\core\management\commands\runserver.py",
line 107, in inner_run
self.check_migrations()
File "c:\venv\lib\site-
packages\django\core\management\commands\runserver.py",
line 159, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "c:\venv\lib\site-packages\django\db\migrations\executor.py", line 17,
in __init__
self.loader = MigrationLoader(self.connection)
File "c:\venv\lib\site-packages\django\db\migrations\loader.py", line 48,
in _
_init__
self.build_graph()
File "c:\venv\lib\site-packages\django\db\migrations\loader.py", line 179,
in
build_graph
self.applied_migrations = recorder.applied_migrations()
File "c:\venv\lib\site-packages\django\db\migrations\recorder.py", line 59,
in
applied_migrations
self.ensure_schema()
File "c:\venv\lib\site-packages\django\db\migrations\recorder.py", line 49,
in
ensure_schema
if self.Migration._meta.db_table in
self.connection.introspection.get_table_
list(self.connection.cursor()):
File "c:\venv\lib\site-packages\django\db\backends\__init__.py", line 167,
in
cursor
cursor = utils.CursorWrapper(self._cursor(), self)
File "c:\venv\lib\site-packages\django\db\backends\__init__.py", line 138,
in
_cursor
self.ensure_connection()
File "c:\venv\lib\site-packages\django\db\backends\__init__.py", line 133,
in
ensure_connection
self.connect()
File "c:\venv\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "c:\venv\lib\site-packages\django\db\backends\__init__.py", line 133,
in
ensure_connection
self.connect()
File "c:\venv\lib\site-packages\django\db\backends\__init__.py", line 122,
in
connect
self.connection = self.get_new_connection(conn_params)
File "c:\venv\lib\site-
packages\django\db\backends\postgresql_psycopg2\base.py
", line 134, in get_new_connection
return Database.connect(**conn_params)
File "c:\venv\lib\site-packages\psycopg2-2.6-py2.7-win-
amd64.egg\psycopg2\__in
it__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: fe_sendauth: no password supplied
Any help ?

Categories