mycli icon indicating copy to clipboard operation
mycli copied to clipboard

Password with @ in it fails when using DSN

Open troy-system76 opened this issue 3 years ago • 8 comments

I use Version: 1.23.2 of mycli.

I have this DSN:

myAlias = mysql://username:passwordWith@and@[email protected]: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

troy-system76 avatar Nov 08 '21 23:11 troy-system76

Hi!

What happens if you run this command?

python -c 'from urllib.parse import urlparse, unquote; uri = urlparse("mysql://username:passwordWith@and@[email protected]: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.

rolandwalker avatar Nov 09 '21 00:11 rolandwalker

Thanks for the quick response. When I run:

python -c 'from urllib.parse import urlparse, unquote; uri = urlparse("mysql://username:passwordWith@and@[email protected]: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@[email protected]: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)

troy-system76 avatar Nov 09 '21 03:11 troy-system76

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.

rolandwalker avatar Nov 09 '21 22:11 rolandwalker

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

liygzting avatar Jan 18 '22 07:01 liygzting

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.

troy-system76 avatar Jan 18 '22 16:01 troy-system76

same issue , because my password contains '#' symbol

ThinkCats avatar Aug 09 '22 02:08 ThinkCats

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

Me too

ThinkCats avatar Aug 09 '22 02:08 ThinkCats

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

afonsocarlos avatar Mar 02 '23 16:03 afonsocarlos