prestodb / presto-python-client

Python DB-API client for Presto
Apache License 2.0
239 stars 87 forks source link

How to provide certificate file when connecting to presto #87

Closed trabbani closed 5 years ago

trabbani commented 5 years ago

I am having this error: (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

when trying to connect to presto using the prestodb client

import prestodb

conn=prestodb.dbapi.connect(
    host='host.name',
    user='myuser',
    catalog='catalog',
    schema='schema',
    port='443',
    http_scheme='https'
)
cur = conn.cursor()
cur.execute('SELECT * FROM table limit 10')
rows = cur.fetchall()

In sqlalchamey I was able to make it work using this code:

engine_presto = create_engine(
    'presto://host.name:443',
    connect_args={
        'protocol': 'https',
        'requests_kwargs': {'verify': '/pat/to/cert.pem'}
    }
)

sql_str = 'SELECT * from table limit 10'
df = pd.read_sql(sql_str, con=engine_presto)

How can I provide my cert.pem file to the prestodb client

trabbani commented 5 years ago

Found the solution:

with prestodb.dbapi.connect(
    host='host.namel',
    port=443,
    user='myuser',
    catalog='catalog',
    schema='schema',
    http_scheme='https'
) as conn:
    conn._http_session.verify = '/path/to/cert.pem'
    cur = conn.cursor()
    cur.execute(sql_str)
cd1986 commented 3 years ago

Found the solution:

with prestodb.dbapi.connect(
    host='host.namel',
    port=443,
    user='myuser',
    catalog='catalog',
    schema='schema',
    http_scheme='https'
) as conn:
    conn._http_session.verify = '/path/to/cert.pem'
    cur = conn.cursor()
    cur.execute(sql_str)

Hi Trabanni,

using the below script I am unable to connect the trino co-ordinator URL, could you please help here?

Python Client

import trino conn = trino.dbapi.connect( host ='[trino host]', port = 8443, user='[user]', catalog ='[catalog]', schema = '[schema]', http_scheme = 'https', auth=trino.auth.BasicAuthentication("[user]". "[password]"), ) conn._http_session.verify = '[certificate path]' cur = conn.cursor() cur.execute('select * from hive.[catalog].[schema])

Error is: ++++++ could not find a suitable TLS CA certificate bundle, invalid path :/tmp/**.crt

sgrbhinge commented 3 years ago

Hello,

can somebody help with the same issue for providing cert file while connecting to Presto using node.js (with package presto-client). Currently I am facing error, unable to get local issuer certificate