Я пытаюсь использовать SQLAlchemy для подключения к базе данных SQL в Azure. У меня есть файл конфигурации со словарем, который содержит аргументы подключения, включая SSL.
При попытке подключения я получаю следующую ошибку.
[SSL] PEM lib (_ssl.c:3499)
Код, который я использую для подключения:
engine = create_engine(conn, connect_args=ssl_args)
cnxn=engine.connect()
Ниже приведена трассировка ...
---------------------------------------------------------------------------
SSLError Traceback (most recent call last)
<ipython-input-16-e7a183ba1dde> in <module>
----> 1 cnxn=engine.connect()
/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in connect(self, **kwargs)
2191 """
2192
-> 2193 return self._connection_cls(self, **kwargs)
2194
2195 @util.deprecated(
/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in __init__(self, engine, connection, close_with_result, _branch_from, _execution_options, _dispatch, _has_events)
101 connection
102 if connection is not None
--> 103 else engine.raw_connection()
104 )
105 self.__transaction = None
/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in raw_connection(self, _connection)
2291 """
2292 return self._wrap_pool_connect(
-> 2293 self.pool.unique_connection, _connection
2294 )
2295
/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _wrap_pool_connect(self, fn, connection)
2260 dialect = self.dialect
2261 try:
-> 2262 return fn()
2263 except dialect.dbapi.Error as e:
2264 if connection is None:
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/base.py in unique_connection(self)
301
302 """
--> 303 return _ConnectionFairy._checkout(self)
304
305 def _create_connection(self):
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/base.py in _checkout(cls, pool, threadconns, fairy)
758 def _checkout(cls, pool, threadconns=None, fairy=None):
759 if not fairy:
--> 760 fairy = _ConnectionRecord.checkout(pool)
761
762 fairy._pool = pool
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/base.py in checkout(cls, pool)
490 @classmethod
491 def checkout(cls, pool):
--> 492 rec = pool._do_get()
493 try:
494 dbapi_connection = rec.get_connection()
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/impl.py in _do_get(self)
137 except:
138 with util.safe_reraise():
--> 139 self._dec_overflow()
140 else:
141 return self._do_get()
/anaconda3/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py in __exit__(self, type_, value, traceback)
66 self._exc_info = None # remove potential circular references
67 if not self.warn_only:
---> 68 compat.reraise(exc_type, exc_value, exc_tb)
69 else:
70 if not compat.py3k and self._exc_info and self._exc_info[1]:
/anaconda3/lib/python3.6/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
127 if value.__traceback__ is not tb:
128 raise value.with_traceback(tb)
--> 129 raise value
130
131 def u(s):
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/impl.py in _do_get(self)
134 if self._inc_overflow():
135 try:
--> 136 return self._create_connection()
137 except:
138 with util.safe_reraise():
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/base.py in _create_connection(self)
306 """Called by subclasses to create a new ConnectionRecord."""
307
--> 308 return _ConnectionRecord(self)
309
310 def _invalidate(self, connection, exception=None, _checkin=True):
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/base.py in __init__(self, pool, connect)
435 self.__pool = pool
436 if connect:
--> 437 self.__connect(first_connect_check=True)
438 self.finalize_callback = deque()
439
/anaconda3/lib/python3.6/site-packages/sqlalchemy/pool/base.py in __connect(self, first_connect_check)
637 try:
638 self.starttime = time.time()
--> 639 connection = pool._invoke_creator(self)
640 pool.logger.debug("Created new connection %r", connection)
641 self.connection = connection
/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py in connect(connection_record)
112 if connection is not None:
113 return connection
--> 114 return dialect.connect(*cargs, **cparams)
115
116 creator = pop_kwarg("creator", connect)
/anaconda3/lib/python3.6/site-packages/sqlalchemy/engine/default.py in connect(self, *cargs, **cparams)
451
452 def connect(self, *cargs, **cparams):
--> 453 return self.dbapi.connect(*cargs, **cparams)
454
455 def create_connect_args(self, url):
/anaconda3/lib/python3.6/site-packages/pymysql/__init__.py in Connect(*args, **kwargs)
92 """
93 from .connections import Connection
---> 94 return Connection(*args, **kwargs)
95
96 from . import connections as _orig_conn
/anaconda3/lib/python3.6/site-packages/pymysql/connections.py in __init__(self, host, user, password, database, port, unix_socket, charset, sql_mode, read_default_file, conv, use_unicode, client_flag, cursorclass, init_command, connect_timeout, ssl, read_default_group, compress, named_pipe, autocommit, db, passwd, local_infile, max_allowed_packet, defer_connect, auth_plugin_map, read_timeout, write_timeout, bind_address, binary_prefix, program_name, server_public_key)
251 self.ssl = True
252 client_flag |= CLIENT.SSL
--> 253 self.ctx = self._create_ssl_ctx(ssl)
254
255 self.host = host or "localhost"
/anaconda3/lib/python3.6/site-packages/pymysql/connections.py in _create_ssl_ctx(self, sslp)
335 ctx.verify_mode = ssl.CERT_NONE if hasnoca else ssl.CERT_REQUIRED
336 if 'cert' in sslp:
--> 337 ctx.load_cert_chain(sslp['cert'], keyfile=sslp.get('key'))
338 if 'cipher' in sslp:
339 ctx.set_ciphers(sslp['cipher'])
SSLError: [SSL] PEM lib (_ssl.c:3499)