1

I'm trying to get a connection from python (3.7) to a remote oracle DB using the code below:

import cx_Oracle # Version 7.2.2
import sshtunnel
import socket

HOST = "HOST"
USRNAME = "Me"
hostname = socket.gethostname()  
IPAddr = socket.gethostbyname(hostname)


with sshtunnel.SSHTunnelForwarder(
                         (HOST, 22), 
                         ssh_username = USRNAME,
                         ssh_pkey='~/.ssh/dumpserver',
                         remote_bind_address=(IPAddr, 22)
                         ) as server: 

        conn = cx_Oracle.connect('testuser','password', 'oracle/db', encoding="UTF-8")
        print(conn.version)

I get the following ERROR:

DatabaseError: ORA-12170: TNS:Connect timeout occurred.

I've tried to read up on this at

But did not get any smarter and I can't get it to work :( Any ideas pointers etc. are very welcome. Also if someone has alternative code snipets on how to send an oracle query to remote - f.eks using paramiko that would be great.

Thanks, F

Raj Paliwal
  • 943
  • 1
  • 9
  • 22
Fabian_G
  • 431
  • 4
  • 16
  • I think your remote_bind_address should probably be `("127.0.0.1",1521)`? Try looking at the SSH tunnel documentation, I think you want Example 1 - https://sshtunnel.readthedocs.io/en/latest/ – kfinity Nov 22 '19 at 17:36
  • See also this example from your third link: https://github.com/oracle/python-cx_Oracle/issues/158#issuecomment-382760857 – kfinity Nov 22 '19 at 17:37
  • Thanks for the suggestion. But the IP is not the problem, I get a working ssh connection with `sshtunnel` (running `server.local_bind_port` returns a port) – Fabian_G Nov 23 '19 at 23:14

1 Answers1

0

I found one Oracle SSH Tunnel code, which is very similar to your code in SSH Tunnel To Server

About the IP issue, your Error code shows that you may have wrong IP for Oracle Service please check this entry lsnrctl status

furkanayd
  • 811
  • 7
  • 19