question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't connect to MySQL server if password contains '#' character

See original GitHub issue

terracotta.get_driver(mysql_path)

Fails when mysql_path contains ‘#’ in any part. It’s actually because of urllib.parse , which fails to parse the URL components if any of the component has ‘#’ in it. There may be other special characters too causing the issue. The password part of the URL has high probability of having these characters. My example :

mysql_path = 'mysql://root:admin#!@123@localhost:3306/db'

Also if you move the ‘#’ around in the password itself, the parsing result is different and hence the errors too

I solved it by using quote/unquote of urllib.parse : mysql_path = 'mysql://root:'+ quote('admin#!@123') + '@localhost:3306/db'

And changed https://github.com/DHI-GRAS/terracotta/blob/5776df9a58cd47b4bf0fcb29070ff40ecdf41d98/terracotta/drivers/mysql.py#L118

password=urlparse.unquote(con_params.password) if con_params.password else None,

Is this solution right way to handle the issue?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
abhi1301commented, Oct 7, 2020

Maybe there is a way to fix this by arguing with the allowed character set of each entity (usernames must be alphanumeric, hostnames US ASCII, …), but I don’t want to be responsible for finding all the edge cases.

Well I looked into the legal characters for username, it seems any ASCII character is allowed, so if there is a colon in the username, it’s ambiguous to differentiate. I tried out some DNS parsers, they all fail. They all assume user to handle the quote/unquote for special cases. But if we are not doing that, I think only choice left is to use env variables.

0reactions
dionhaefnercommented, Oct 8, 2020

Config variables incoming in #188.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mysql command line password with special characters is not ...
Logging into mysql using bash. For ubuntu or linux shell try to use command mysql -u username -p'p@ssw()rD'. for remote host login use...
Read more >
4.14 Troubleshooting Problems Connecting to MySQL
The server should let you connect because the MySQL root user has no password initially. That is also a security risk, so setting...
Read more >
Bug #1598992 “MySQL Server installation fails if root ...
The postinst script for mysql-server-5.7 can take a root password for the server as input. It does not properly escape this password before ......
Read more >
mysql_connect - Manual - PHP
mysql_connect — Open a connection to a MySQL Server ... variables_order configure directive doesn't contain character E . On Windows, if the environment...
Read more >
mysql connection from bash shell with special characters in ...
The correct syntax which should get executed is mysql --host=localhost --user=root --password='>fjkIyu#K7T?' Please see, if any changes i need ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found