./main.py运行错误

来源:3-17 邮件发送功能代码实现 mp4

weixin_慕无忌8315996

2019-10-11

[root@bogon imoocc_py3_online]# ./main.py
…ssh ip list {}
Password Login … {} {}
Key Login … {} {}
(535, b’Error: authentication failed’)
Traceback (most recent call last):
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 213, in ensure_connection
self.connect()
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 189, in connect
self.connection = self.get_new_connection(conn_params)
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/mysql/base.py”, line 274, in get_new_connection
conn = Database.connect(**conn_params)
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/init.py”, line 90, in Connect
return Connection(*args, **kwargs)
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 699, in init
self.connect()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 936, in connect
self._request_authentication()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 1156, in _request_authentication
auth_packet = self._read_packet()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 1018, in _read_packet
packet.check_error()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 384, in check_error
err.raise_mysql_exception(self._data)
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/err.py”, line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, “Access denied for user ‘imoocc’@‘localhost’ (using password: YES)”)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “./main.py”, line 201, in
main()
File “./main.py”, line 76, in main
unkown_list,key_not_login_list = snmp_begin(nmap_type,s_ports,s_pass,s_keys,s_cmds,s_blacks,s_emails)
File “/usr/local/imoocc_py3_online/scanhosts/util/nmap_all_server.py”, line 70, in snmp_begin
HostLoginifo.objects.filter(ip__contains=nmap_type).delete()
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/query.py”, line 617, in delete
deleted, _rows_count = collector.delete()
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/deletion.py”, line 274, in delete
with transaction.atomic(using=self.using, savepoint=False):
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/transaction.py”, line 158, in enter
if not connection.get_autocommit():
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 385, in get_autocommit
self.ensure_connection()
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 213, in ensure_connection
self.connect()
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/utils.py”, line 94, in exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File “/usr/local/python3.6/lib/python3.6/site-packages/django/utils/six.py”, line 685, in reraise
raise value.with_traceback(tb)
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 213, in ensure_connection
self.connect()
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 189, in connect
self.connection = self.get_new_connection(conn_params)
File “/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/mysql/base.py”, line 274, in get_new_connection
conn = Database.connect(**conn_params)
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/init.py”, line 90, in Connect
return Connection(*args, **kwargs)
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 699, in init
self.connect()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 936, in connect
self._request_authentication()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 1156, in _request_authentication
auth_packet = self._read_packet()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 1018, in _read_packet
packet.check_error()
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/connections.py”, line 384, in check_error
err.raise_mysql_exception(self._data)
File “/usr/local/python3.6/lib/python3.6/site-packages/pymysql/err.py”, line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.OperationalError: (1045, “Access denied for user ‘imoocc’@‘localhost’ (using password: YES)”)

写回答

2回答

Jeson

2019-10-11

imoocc程序连接报错的方式是:

 “Access denied for user ‘imoocc’@‘localhost’ (using password: YES)”

而你测试用的

mysql -u root -p"1qaz@WSX"可以登录


所以配置的用户密码不对。

//img1.sycdn.imooc.com/szimg/5da0461109a28c7107510441.jpg

0
0

weixin_慕无忌8315996

提问者

2019-10-11

setting涉及数据库设置

 DATABASES = {

     'default': {

         'ENGINE': 'django.db.backends.mysql',

         'NAME': 'imoocc',

         'USER': 'imoocc',

         'PASSWORD': '1qaz@WSX',

         'HOST': '127.0.0.1',

         'PORT': '',

         'OPTIONS': {},

         'init_command': 'SET storage_engine=INNODB,'

                         'SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED, autocommit=1, names "utf8";',

mysql -u root -p"1qaz@WSX"可以登录

可以查到用户

mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

+------------------------------------+

| query                              |

+------------------------------------+

| User: 'imoocc'@'127.0.0.1';        |

| User: 'root'@'127.0.0.1';          |

| User: 'mysql.session'@'localhost'; |

| User: 'mysql.sys'@'localhost';     |

| User: 'root'@'localhost';          |


0
0

Python+Django+Ansible Playbook自动化运维项目实战

【课程升级3.6版本】大牛全面践行DevOps,运维与开发间高效协作

861 学习 · 326 问题

查看课程