Thanks to visit codestin.com
Credit goes to github.com

Skip to content

read_default_file doesn't work for SSL parameters #1020

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

Closed
ryantm opened this issue Jan 20, 2022 · 4 comments · Fixed by #1114
Closed

read_default_file doesn't work for SSL parameters #1020

ryantm opened this issue Jan 20, 2022 · 4 comments · Fixed by #1114
Milestone

Comments

@ryantm
Copy link

ryantm commented Jan 20, 2022

Describe the bug
I am trying to use read_default_file to configure the pymysql connection

To Reproduce

Use pymysql version 1.0.2.

Have a mysql config file like:

[mysql]
comments=1
default-character-set = utf8mb4
host = databasehost.example.com
database = dbname
ssl_key = /etc/mysql/client/key.pem
ssl_cert = /etc/mysql/client/cert.pem
ssl_ca = /etc/mysql/client/ca.pem

Code:

import pymysql
conn = pymysql.connect(
          read_default_file=database_default_file,
          read_default_group='mysql',
          user=username, password=password, autocommit=True)

and if the user grant requires SSL it fails to connect.

If I change the code to

import pymysql
conn = pymysql.connect(
          read_default_file=database_default_file,
          read_default_group='mysql',
          user=username, password=password, autocommit=True,
          ssl_ca="/etc/mysql/client/ca.pem",
          ssl_cert= "/etc/mysql/client/cert.pem",
          ssl_key="/etc/mysql/client/key.pem")

It connects

Expected behavior

The ssl parameters don't have to be separately specified.

Environment

  • OS: NixOS
  • Server and version: mysql Ver 15.1 Distrib 10.1.47-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
  • PyMySQL version: 1.0.2

Additional context
Add any other context about the problem here.

@methane
Copy link
Member

methane commented Jan 20, 2022

Would you try to replace this "-" with "_"?

value = _config("ssl-" + key, ssl.get(key))

@ryantm
Copy link
Author

ryantm commented Jan 20, 2022

Thanks. Changing the config file's fields from "_" to "-" like

[mysql]
comments=1
default-character-set = utf8mb4
host = databasehost.example.com
database = dbname
ssl-key = /etc/mysql/client/key.pem
ssl-cert = /etc/mysql/client/cert.pem
ssl-ca = /etc/mysql/client/ca.pem

made it work. The MySQL CLI supports either dash or underscore there (as dones Ruby's mysql), so I think it makes sense for PyMySQL to support either one too.

@alimp5
Copy link

alimp5 commented Oct 2, 2022

Dear @ryantm,
I'm thankful if it's possible, Plz tell me difference between ssl-cert, ssl-ca, ssl-key.
thanks you.

@ryantm
Copy link
Author

ryantm commented Oct 2, 2022

@alimp5 as far as MySQL is concerned they are the same, but this library treats them differently.

@methane methane added this to the v1.1 milestone May 24, 2023
methane added a commit to methane/PyMySQL that referenced this issue May 24, 2023
methane added a commit that referenced this issue May 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants