By changing the dsn from localhost/service_name
to actual dsn string present in tnsnames.ora file, it worked.
dsn = "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=localhost))(connect_data=(service_name=service_name))(security=(ssl_server_dn_match=no)))"