Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias_dsn password suffix with # will panic #585

Closed
ajaxmao opened this issue Mar 17, 2018 · 5 comments
Closed

alias_dsn password suffix with # will panic #585

ajaxmao opened this issue Mar 17, 2018 · 5 comments

Comments

@ajaxmao
Copy link

ajaxmao commented Mar 17, 2018

Traceback (most recent call last):
File "/usr/bin/mycli", line 11, in
sys.exit(cli())
File "/usr/lib/python2.7/site-packages/click/core.py", line 716, in call
return self.main(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/usr/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/mycli/main.py", line 1027, in cli
mycli.connect_uri(database, local_infile, ssl)
File "/usr/lib/python2.7/site-packages/mycli/main.py", line 285, in connect_uri
uri.port, local_infile=local_infile, ssl=ssl)
File "/usr/lib64/python2.7/urlparse.py", line 112, in port
port = int(port, 10)
ValueError: invalid literal for int() with base 10:

@meeuw
Copy link
Contributor

meeuw commented Mar 17, 2018

This is certainly a bug but could you try to surround the dsn with quotes? Like:

[alias_dsn]
test = "mysql://user:pa##@host"

?

@ajaxmao
Copy link
Author

ajaxmao commented Mar 18, 2018

I try to surround the dsn with quotes, but it's helpless.

I think the '# ‘’ is used for fragments,and the default value of allow_fragments is True.

<scheme>://<netloc>/<path>;<params>?<query>#<fragment>

I try to change function _splitnetloc in urlparse, it's helpful

//urlparse lib

def _splitnetloc(url, start=0):
    delim = len(url)   # position of end of domain part of url, default is end
    location_at = url.find('@')
    for c in '/?#':    # look for delimiters; the order is NOT important
        wdelim = url.find(c, start)        # find first of this delim      
        if wdelim >= 0 and wdelim > location_at:                    # if found
            delim = min(delim, wdelim)     # use earliest delim position   
    return url[start:delim], url[delim:]   # return (domain, rest)

@meeuw
Copy link
Contributor

meeuw commented Mar 18, 2018

Hmm I don't think patching system libraries is a good idea... Have you tried replacing '#' with %23 in your password?

Like this:

[alias_dsn]
test = "mysql://user:pa%23%23@host"

@ajaxmao
Copy link
Author

ajaxmao commented Mar 24, 2018

Thanks,it‘s a good idea ’to use 23% and Unquote . But may cause another issue to happen if '%23' is just a part of my password. 囧...

@meeuw
Copy link
Contributor

meeuw commented Mar 25, 2018

% can be escaped by using %25, so if your password contains %23 that would become %2523.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants