Forum Stats

  • 3,874,696 Users
  • 2,266,767 Discussions
  • 7,911,952 Comments

Discussions

OracleDB does not work in Python 3.9.13 on Cloud ADB

fmz
fmz Member Posts: 73 Blue Ribbon

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

  • Christopher Jones-Oracle
    Christopher Jones-Oracle Member Posts: 1,656 Employee
    edited Jun 8, 2022 9:56PM 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

    User_LZNV6

Answers

  • Christopher Jones-Oracle
    Christopher Jones-Oracle Member Posts: 1,656 Employee
    edited Jun 8, 2022 9:56PM 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

    User_LZNV6
  • fmz
    fmz Member Posts: 73 Blue Ribbon

    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