Improper error shown - (2003, "Can't connect to MySQL server on 'localhost'")
See original GitHub issueDescribe the bug
Well I formatted my pc and had to reinstall all the stuff and while I started working with my code I started receiving error (2003, "Can't connect to MySQL server on 'localhost'")
I was not expecting that as my code worked flawless and at that time my discord bot which uses the same code was up and running well. So after two hours of going through all code I found that I had added db
parameter in aiomysql.create_pool
and I had forgot to create a database with the db mentioned there so that was the problem! So what I want is it should throw error that db is not found
rather than (2003, "Can't connect to MySQL server on 'localhost'")
To Reproduce
I am running latest version of python 3.10 and pip installed aiomysql
Just dont make a database and try creating aiomysql.create_pool
object with mentioning db you will get the error!
I used following code:
import asyncio
import aiomysql
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
async def test_example():
try:
conn = await aiomysql.create_pool(host='localhost', port=3306, user='user', password='pass',loop=loop,db="uncreated_db")
except Exception as e:
print(e)
loop.run_until_complete(test_example())
Expected behavior
Will throw this error : (2003, "Can't connect to MySQL server on 'localhost'")
Logs/tracebacks
Will throw this error : ``(2003, "Can't connect to MySQL server on 'localhost'")``
Python Version
$ Python 3.10.4
aiomysql Version
$ python -m pip show aiomysql
PyMySQL Version
1.0.2
SQLAlchemy Version
1.0.2
OS
Windows
Database type and version
MySQL : 8.0.29
Additional context
No response
Code of Conduct
- I agree to follow the aio-libs Code of Conduct
Issue Analytics
- State:
- Created a year ago
- Comments:6
#839 should resolve this.
Why do we have this bit of code:
Instead of raising the original exception? We lose all the info and the error code (auth failed for 1045 for example, 1049 database not found, etc).
This approach does not make much sense, putting everything as an Operational Error 2003 code.
https://github.com/aio-libs/aiomysql/blob/814d07266e0ac16eee0ca25f97691f6c7d4db4af/aiomysql/connection.py#L553