pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.78k stars 298 forks source link

Database password with square brackets #318

Closed Johan944 closed 4 years ago

Johan944 commented 4 years ago

Hello, we try to use your module but we met a problem.

When we try to connect with our production database, an error occured : -> File "C:\Users\Johan Ganem--Brunet\Anaconda3\lib\urllib\parse.py", line 459, in urlsplit raise ValueError("Invalid IPv6 URL") ValueError: Invalid IPv6 URL

While in local, there is not problem.

I researched in the Internet, and I found that urllib does not support brackets in URL. So, the password in brackets must to be encode, but when a I did this, a sqlalchemy error occured: -> sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string

Can you think you can fix that ? Thank you :)

Johan

pudo commented 4 years ago

Can you test if this problem also exists if you use SQLAlchemy without dataset? If so, I'd recommend reporting the issue upstream in the SQLAlchemy bug tracker.

Johan944 commented 4 years ago

Thank you for your quick response !

I already use SQLAlchemy with our url, and there is not any problem with square brackets in password.

Johan944 commented 4 years ago

I found a solution :

from urllib.parse import quote_plus as urlquote

url = f"mysql://{user}:{urlquote(password)}@{host}/{db_name}"
db = dataset.connect(url)
pudo commented 4 years ago

Ah, interesting, thanks!