Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 439 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
OracleDB does not work in Python 3.9.13 on Cloud ADB
Hi,
I am trying to connect to my Always Free ADB with Python 3.9.13 (fresh installed today) and OracleDB
without success:
Traceback (most recent call last):
connection = oracledb.connect(user='northwind', password='blahblah', dsn='db21cpresent_medium')
File "C:\Python39\lib\site-packages\oracledb\connection.py", line 995, in wrapped
return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
File "C:\Python39\lib\site-packages\oracledb\connection.py", line 124, in __init__
impl.connect(params_impl)
File "src\oracledb\impl/thin/connection.pyx", line 309, in oracledb.thin_impl.ThinConnImpl.connect
File "src\oracledb\impl/thin/connection.pyx", line 164, in oracledb.thin_impl.ThinConnImpl._connect_with_params
File "src\oracledb\impl/thin/crypto.pyx", line 125, in oracledb.thin_impl.get_ssl_socket
File "C:\Python39\lib\ssl.py", line 501, in wrap_socket
return self.sslsocket_class._create(
File "C:\Python39\lib\ssl.py", line 1041, in _create
self.do_handshake()
File "C:\Python39\lib\ssl.py", line 1310, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1129)
The same connection works with cx_Oracle fine.
Regards, Friedhold
Best Answer
-
Read the documentation: https://python-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#connecting-to-oracle-cloud-autonomous-databases
The default 'Thin' mode of python-oracledb you are using needs the wallet in PEM file format. This is a requirement of the Python libraries now being used, since Thin mode doesn't use the Oracle Client libraries (which use a .sso file). Recent wallet.zip files include a .pem file. If you don't have one, then re-download the wallet.zip file. Or you can convert the .p12 file in your wallet.zip to a .pem file using the utility script in the documentation.
Pass the directory (not including the filename) containing the wallet when you connect. You also need to specify the wallet password:
connection = oracledb.connect(user='northwind', password=pw, dsn='db21cpresent_medium',
config_dir="c:\the\dir\containing\the\tnsnames\file",
wallet_location=r"c:\the\dir\containing\the\pem\file", wallet_password=wpw,
)
Alternatively, enable 'Thick' mode and you won't need the above.
A third option is to use 1-way TLS. That is also in the documentation
Answers
-
Read the documentation: https://python-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#connecting-to-oracle-cloud-autonomous-databases
The default 'Thin' mode of python-oracledb you are using needs the wallet in PEM file format. This is a requirement of the Python libraries now being used, since Thin mode doesn't use the Oracle Client libraries (which use a .sso file). Recent wallet.zip files include a .pem file. If you don't have one, then re-download the wallet.zip file. Or you can convert the .p12 file in your wallet.zip to a .pem file using the utility script in the documentation.
Pass the directory (not including the filename) containing the wallet when you connect. You also need to specify the wallet password:
connection = oracledb.connect(user='northwind', password=pw, dsn='db21cpresent_medium',
config_dir="c:\the\dir\containing\the\tnsnames\file",
wallet_location=r"c:\the\dir\containing\the\pem\file", wallet_password=wpw,
)
Alternatively, enable 'Thick' mode and you won't need the above.
A third option is to use 1-way TLS. That is also in the documentation
-
Great thanks, Christopher!
It works with the specification of the three parameters (Windows 10) now:
connection = oracledb.connect(user='northwind', password=pw, dsn='db21cpresent_medium',
config_dir="c:\\my\\wallet\\dir",
wallet_location="c:\\my\\wallet\\dir",
wallet_password=wpw
)
In my wallet-dir there are the tnsname.ora and ewallet.pem files after unzipping of the wallet.zip file.
Ciao, Friedhold