반응형
python->SQ에서 mysql(MariaDB)에 대한 접속이 실패함cmd에 성공하는 동안 LALchemy
db_url을 사용하여 플라스크 앱 내의 보안 옵션을 사용하여 원격 mysql(MariaDB) 데이터베이스에 연결하려고 합니다.간단한 테스트 버전:
from sqlalchemy import create_engine
engine = create_engine(
'mysql+mysqlconnector://user:password@remote.host.com:3306/mydb?'+
'ssl_key=/path/to/key.pem'+
'&ssl_cert=/path/to/scrt.crt'
)
connection = engine.connect()
SSL 문제로 이어지는 오류 발생
sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) 2026 (HY000): SSL connection error: error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol
(Background on this error at: http://sqlalche.me/e/rvf5)
(mysql 커넥터 대신 pymysql도 시도해 보았습니다)
다만, 커맨드 라인에서 접속하려고 하면(이해할 수 없는 것) 동작합니다.
mysql -u user -ppassword mydb -h remote.host.com --ssl-cert=/path/to/scrt.crt --ssl-key=/path/to/key.pem
만약을 위해:
> SHOW VARIABLES LIKE "%version%";
+-----------------------------------+------------------------------------------+
| Variable_name | Value |
+-----------------------------------+------------------------------------------+
| in_predicate_conversion_threshold | 1000 |
| innodb_version | 10.3.34 |
| protocol_version | 10 |
| slave_type_conversions | |
| system_versioning_alter_history | ERROR |
| system_versioning_asof | DEFAULT |
| version | 10.3.34-MariaDB-0ubuntu0.20.04.1 |
| version_comment | Ubuntu 20.04 |
| version_compile_machine | x86_64 |
| version_compile_os | debian-linux-gnu |
| version_malloc_library | system |
| version_source_revision | a36fc80aeb3f835fad02f443d65dc608b74b92d1 |
| version_ssl_library | YaSSL 2.4.4 |
| wsrep_patch_version | wsrep_25.24 |
+-----------------------------------+------------------------------------------+
혹시나 해서.openssl 구성에서도/etc/ssl/openssl.cnf
( remote.host.com이 아닌 서버1).
...
[system_default_sect]
MinProtocol = TLSv1.1
...
주의: 최근 서버를 Ubuntu 20.04.4 LTS로 업데이트하고 python을 3.8.10으로 업데이트했습니다(관련없을 수도 있습니다).
여러 번 조사해 본 결과, 문제는 리모트 데이터베이스의 구식 버전으로 판명되었습니다.업그레이드 후에는 모든 것이 정상적으로 동작합니다.
데이터베이스에서 사용된 TLS 버전이 너무 안전하지 않은 것으로 알고 있습니다(에 존재하지 않음).%version%
변수).업그레이드 후 다음과 같은 결과를 얻었습니다.
tls_version | TLSv1.1,TLSv1.2,TLSv1.3
클라이언트의 openssl에서 필요한 버전과 호환됩니다( ).MinProtocol = TLSv1.1
)
언급URL : https://stackoverflow.com/questions/71547771/connection-to-mysql-mariadb-fails-in-python-sqlalchemy-while-it-succeeds-in-c
반응형
'programing' 카테고리의 다른 글
왜 PHP에서 sprintf 함수를 사용하는가? (0) | 2023.01.25 |
---|---|
PHP의 self::$bar와 static:$bar의 차이점은 무엇입니까? (0) | 2023.01.25 |
스핑크스의 자동화가 불충분하다 (0) | 2023.01.15 |
Android 응용 프로그램의 QR 코드를 생성하는 방법은 무엇입니까? (0) | 2023.01.15 |
외부 키 제약 테이블을 잘라내는 방법 (0) | 2023.01.15 |