Issue
I am running a flask web server on localhost. I am trying to connect a mysql database but it gave me this error:
pymysql.err.OperationalError: (1045, "Access denied for user 'IMRAN'@'localhost' (using password: NO)")
I have tried everything including research on internet but not yet be successful. even i have reinstalled xampp server. All privileges given to User 'IMRAN'@'localhost'. but it did not work.
Still gave me same error. My dbdconfig code is here:
from app import app
from flaskext.mysql import MySQL
mysql = MySQL()
app.config['MYSQL_USER'] = 'IMARN'
app.config['MYSQL_PASSWORD'] = '12345678'
app.config['MYSQL_DB'] = 'naam'
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_PORT'] = 3306
mysql.init_app(app)
You can Read all errors here:
127.0.0.1 - - [10/Sep/2022 19:53:31] "GET /readall HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2548, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2528, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_cors\extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "C:\Users\IMRAN\Desktop\pythonweb\api\main.py", line 37, in read_name
con = mysql.connect()
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\flaskext\mysql.py", line 65, in connect
return pymysql.connect(**self.connect_args)
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 353, in __init__
self.connect()
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 633, in connect
self._request_authentication()
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 907, in _request_authentication
auth_packet = self._read_packet()
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 725, in _read_packet
packet.raise_for_error()
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "C:\Users\IMRAN\AppData\Local\Programs\Python\Python310\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'IMRAN'@'localhost' (using password: NO)")
127.0.0.1 - - [10/Sep/2022 19:53:31] "GET /readall?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 304 -
127.0.0.1 - - [10/Sep/2022 19:53:31] "GET /readall?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 304 -
127.0.0.1 - - [10/Sep/2022 19:53:31] "GET /readall?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 304 -
127.0.0.1 - - [10/Sep/2022 19:53:31] "GET /readall?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
HERE IS GRANT PRIVILEGES CHECK:
+-----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for IMRAN@localhost |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `IMRAN`@`localhost` IDENTIFIED BY PASSWORD '*00A51F3F48415C7D4E8908980D443C29C69B60C9' WITH GRANT OPTION |
| GRANT ALL PRIVILEGES ON `naam`.* TO `IMRAN`@`localhost` WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
Solution
The error is due to username confusion :
For this instruction : app.config['MYSQL_USER'] = 'IMARN'
, you set username as IMARN.
So user IMRAN doesn't exists.
Answered By - nissim abehcera
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.