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

MySQLDsn build failed if password contains special character #1467

Open
zh0uquan opened this issue Sep 24, 2024 · 1 comment
Open

MySQLDsn build failed if password contains special character #1467

zh0uquan opened this issue Sep 24, 2024 · 1 comment

Comments

@zh0uquan
Copy link

Hello, running the following code to build mysql url will cause a error when password contains a special character #.

from pydantic import MySQLDsn
MySQLDsn.build(
      scheme="mysql+aiomysql",
      username="test", 
      password="test#1", 
      host="127.0.0.1", 
      port=3306, 
     path="test"
)

this is the error message

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pydantic_core._pydantic_core.ValidationError: 1 validation error for url
  Input should be a valid URL, invalid port number [type=url_parsing, input_value='mysql+aiomysql://test:test#[email protected]:3306/test', input_type=str]
@praveenram
Copy link

I ran into this today and found that quoting the password addressed the problem, ref: https://stackoverflow.com/questions/1423804/writing-a-connection-string-when-password-contains-special-characters

It would be great to automatically quote the password in the build method though.

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