dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.41k stars 658 forks source link

Password with @ in it fails when using DSN #1012

Open troy-system76 opened 2 years ago

troy-system76 commented 2 years ago

I use Version: 1.23.2 of mycli.

I have this DSN:

myAlias = mysql://username:passwordWith@and@m@host.rds.amazonaws.com:5555/mydb

(a bunch of stuff is changed there)

But when I go:

mycli myAlias

I receive this error:

(2003, "Can't connect to MySQL server on '}gg$' ([Errno -2] Name or service not known)")

If I encode the uri with %40 for the @ signs I receive this error:

Traceback (most recent call last):
  File "/usr/bin/mycli", line 33, in <module>
    sys.exit(load_entry_point('mycli==1.23.2', 'console_scripts', 'mycli')())
  File "/home/troy/.local/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/troy/.local/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/troy/.local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/troy/.local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/mycli/main.py", line 1191, in cli
    user = unquote(uri.username)
  File "/usr/lib/python3.9/urllib/parse.py", line 654, in unquote
    if '%' not in string:
TypeError: argument of type 'NoneType' is not iterable

Do you know how I can make mycli work with @ in the passwords?

Thanks in advance

rolandwalker commented 2 years ago

Hi!

What happens if you run this command?

python -c 'from urllib.parse import urlparse, unquote; uri = urlparse("mysql://username:passwordWith@and@m@host.rds.amazonaws.com:5555/mydb"); print(uri.username); print(uri.password);'

Here I get

username
passwordWith@and@m

suggesting that @ symbols alone are not the source of your issue.

troy-system76 commented 2 years ago

Thanks for the quick response. When I run:

python -c 'from urllib.parse import urlparse, unquote; uri = urlparse("mysql://username:passwordWith@and@m@host.rds.amazonaws.com:5555/mydb"); print(uri.username); print(uri.password);'

I get:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named parse

if I run:

python3 -c 'from urllib.parse import urlparse, unquote; uri = urlparse("mysql://username:passwordWith@and@m@host.rds.amazonaws.com:5555/mydb"); print(uri.username); print(uri.password);'

I get the same response you do.

/usr/bin/mycli has this:

!/usr/bin/python3

Not that that means much. it's a tiny script that looks like it calls something else (apologies, I have very little python experience)

rolandwalker commented 2 years ago

You might want to take a look at the python3 -c output but using your actual DSN instead of the example we are using.

Our example works for both of us, but maybe your actual DSN does not.

liygzting commented 2 years ago

when # in the url will get error python -c 'from urllib.parse import urlparse, unquote; uri = urlparse("mysql://root:pken3I#l1@10.10.20.211:29119/mydatabasess"); print(uri.username); print(uri.password);' --------> None None

troy-system76 commented 2 years ago

Going out on a limb I'd say that I and @liygzting are missing a library that enables us to properly use special characters in passwords.

ThinkCats commented 2 years ago

same issue , because my password contains '#' symbol

ThinkCats commented 2 years ago

when # in the url will get error python -c 'from urllib.parse import urlparse, unquote; uri = urlparse("mysql://root:pken3I#l1@10.10.20.211:29119/mydatabasess"); print(uri.username); print(uri.password);' --------> None None

Me too

afonsocarlos commented 1 year ago

url encoding # character into %23 as suggested here https://github.com/dbcli/mycli/issues/585#issuecomment-373989269 worked well for me!