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

OperationalError: 1045 on login if password has non ascii characters #804

Closed
Zincr0 opened this issue Aug 14, 2019 · 2 comments
Closed

OperationalError: 1045 on login if password has non ascii characters #804

Zincr0 opened this issue Aug 14, 2019 · 2 comments

Comments

@Zincr0
Copy link

Zincr0 commented Aug 14, 2019

OperationalError: 1045 on login if password has non ascii characters

  • Using python 3.5

Step to reproduce:

1.- Install PyMySQL[rsa] and cryptography.

2.- Create a mysql 8 instance

docker run --name some-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-sécrét-pw -e MYSQL_DATABASE=dbase -d mysql:8.0

3.- Wait like 10 seconds to the container fully starts.

4.- Try to connect

import pymysql.cursors
connection = pymysql.connect(host='127.0.0.1',
                             user='root',
                             password='my-sécrét-pw',
                             db='dbase')

It will fail with
OperationalError: (1045, "Access denied for user 'root'@'172.17.0.1' (using password: YES)")

However, if you use an ascii password like "my-secret-pw", it will work just fine.

@methane
Copy link
Member

methane commented Aug 15, 2019

This is not a bug because MySQL protocol doesn't define which encoding is used to encode password. So library can't guarantee login is succeeded when password is non-ASCII unicode.
You can manually encode your password and pass the binary password to PyMySQL.

@methane methane closed this as completed Aug 15, 2019
@Zincr0
Copy link
Author

Zincr0 commented Aug 17, 2019

I will leave here a working example for everyone, since there is no documentation about this "not a bug" thing that affects only this library:

import pymysql.cursors
connection = pymysql.connect(host='127.0.0.1',
                             user='root',
                             password=bytes('my-sécrét-pw', 'utf-8') ,
                             db='dbase')

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants