You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env python3importasynciofromasyncmyimportconnectasyncdefmain():
print("# Using asyncmy directly")
try:
conn=awaitconnect(
host="myhost",
user="myuser",
password="mypassword",
database="mydatabase",
)
exceptExceptionase:
print(e)
print("# Using asyncmy directly with a config file")
try:
conn=awaitconnect(read_default_file="bug.cnf")
exceptExceptionase:
print(e)
if__name__=="__main__":
asyncio.run(main())
This is the output of the script:
./bug.py
# Using asyncmy directly
(2003, "Can't connect to MySQL server on 'myhost' ([Errno -2] Name or service not known)")
# Using asyncmy directly with a config file
(1045, "Access denied for user 'myuser'@'localhost' (using password: YES)")
You can see that:
In the first try, asyncmy tries to connect to host=myhost (correct)
In the second try, asyncmy tries to connect to user=myuser (correct) and host=localhost (wrong)
The reason of this bug is placed in the object Connection (connection.pyx). We have this function to read the data from the config file:
but host and port defaults ('localhost' and 3306 respectively) are not evaluated to "False", so the corresponding values won't be readed from file:
def__init__(
self,
*,
user=None, # The first four arguments is based on DB-API 2.0 recommendation.password="",
host='localhost',
database=None,
unix_socket=None,
port=3306,
...
):
Hi,
I've tried to start a connection with asyncmy taking the connection parameters from a config file.
This is my config file (
bug.cnf
):I've prepared this script to show the problem:
This is the output of the script:
You can see that:
The reason of this bug is placed in the object Connection (connection.pyx). We have this function to read the data from the config file:
Note that the value of
arg
has a higher priority over the value obtained from the config file, which is requested only whenarg
is evaluated asFalse
.Then, we execute this function setting
arg
to the defaults:but
host
andport
defaults ('localhost' and 3306 respectively) are not evaluated to "False", so the corresponding values won't be readed from file:The solution is to set these defaults to:
host
=None
port
=0
In PyMySQL this bug is already fixed:
Thanks and greetings,
Pedro
The text was updated successfully, but these errors were encountered: