Доступ запрещен Django: (1045, «Доступ запрещен для пользователя 'darth_vader'@'151.33.241.48' (с использованием пароля: ДА)») - PullRequest
2 голосов
/ 20 июня 2020

Я использую django 3.0 и использую MySQL базу данных для своего веб-приложения. Мой код settings.py:

    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',
   }
}

И вместо подключения к admin@151.33.241.48 он подключается к имени пользователя darth_vader. Имя darth_vader - это домашнее имя пользователя моей машины ubantu (локальная среда разработки).

Я вижу «darth_vader@Rushikesh-HP: ~ $», когда открываю свой терминал.

Сообщение об ошибке:

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)")

Есть ли какие-либо изменения конфигурации или настройки, чтобы я мог запустить свое приложение.

1 Ответ

3 голосов
/ 20 июня 2020

Клавиша для указания имени пользователя: 'USER' [Django -doc] , а не 'USERNAME'. Как указано в документации:

USER

По умолчанию: '' (Пустая строка)

Имя пользователя для используйте при подключении к базе данных. Не используется с SQLite.

Таким образом, вы должны исправить это с помощью:

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'thirdihrms',
    <b>'USER': 'admin',</b>  # <i>no</i> <s>USERNAME</s>
    'PASSWORD': 'xxxxxxxx',
    'HOST': 'database-1.xxxxxxxxx.us-east-1.rds.amazonaws.com',
    'PORT': '3306',
   }
}
...