Big Data 6 min read

How to Connect Python to Presto on Huawei MRS: Step-by-Step Guide & Common Pitfalls

Learn how to set up a Python environment on an Ubuntu ECS, install the presto‑python‑client and PyHive libraries, configure Kerberos and SSL credentials, run sample queries against a Presto coordinator, and avoid typical errors such as NTP, SSL and authentication issues.

Huawei Cloud Developer Alliance
Huawei Cloud Developer Alliance
Huawei Cloud Developer Alliance
How to Connect Python to Presto on Huawei MRS: Step-by-Step Guide & Common Pitfalls

Python libraries for connecting to Presto

Two open‑source libraries are available: presto‑python‑client (https://github.com/prestodb/presto-python-client) and PyHive (https://github.com/dropbox/PyHive).

Environment preparation

1. Create an Ubuntu ECS instance with the same VPC as the MRS cluster.

2. Install apt‑get, pip3, python3.

3. Install the MRS client.

Reference: https://support.huaweicloud.com/usermanual-mrs/mrs_01_0091.html

Encountered error: "Error: Network time protocol(NTP) not running. Please start NTP first."

Solution: sudo /etc/init.d/ntp restart 4. In MRS Manager, create a user, download authentication credentials, extract krb5.conf and user.keytab to /root.

5. Copy the cluster's SSL certificate (cacert.pem) to /root on the Ubuntu ECS.

Connection method: presto‑python‑client

Install dependencies:

pip3 install pandas

sudo apt‑get install python3‑dev

sudo apt install krb5‑multidev

pip3 install requests_kerberos

pip3 install presto‑python‑client

Code example:

import prestodb
import os
from pandas import DataFrame
os.system('kinit -kt {}/user.keytab {}'.format('/root','sxy'))

conn = prestodb.dbapi.connect(
    host='192.168.0.194',
    port=7521,
    user='sxy',
    catalog='tpcds',
    schema='sf1',
    http_scheme='https',
    auth=prestodb.auth.KerberosAuthentication(
        config='/root/krb5.conf',
        service_name='presto',
        principal='sxy',
        mutual_authentication=False,
        ca_bundle='/root/cacert.pem')
)

cur = conn.cursor()
cur.execute('select c_first_name, c_last_name from customer limit 5')
df = DataFrame(cur.fetchall())
df.columns = ['First_Name', 'Last_Name']
print(df)

Result screenshot:

Connection method: PyHive

Install dependencies:

sudo apt‑get install python3-dev

sudo apt install krb5‑multidev

pip3 install requests_kerberos

pip3 install pyhive

Code example:

from pyhive import presto
presto_cli = presto.connect(
    host='192.168.0.194',
    port=7521,
    username='sxy',
    password='XXXX',
    catalog='tpcds',
    schema='sf1',
    poll_interval=1,
    source='pyhive',
    session_props=None,
    protocol='https',
    requests_kwargs={'verify':'/root/cacert.pem'},
    KerberosRemoteServiceName='presto',
    KerberosPrincipal='sxy',
    KerberosConfigPath='/root/krb5.conf',
    KerberosKeytabPath='/root/user.keytab',
    KerberosCredentialCachePath=None,
    KerberosUseCanonicalHostname=None
)

c = presto_cli.cursor()
c.execute('show tables')
for i in c.fetchall():
    print(i)

Result screenshot:

Common pitfalls

On EulerOS, missing header files for requests‑kerberos; switched to Ubuntu.

SSL authentication failures caused by incorrect PEM file configuration.

401 Unauthorized errors due to misconfigured Kerberos parameters (user, principal, krb5.conf, keytab).

Validate parameters by logging in with presto_cli and executing show tables; success indicates correct configuration.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Big DataPythonSSLPrestoKerberosUbuntuPyHive
Huawei Cloud Developer Alliance
Written by

Huawei Cloud Developer Alliance

The Huawei Cloud Developer Alliance creates a tech sharing platform for developers and partners, gathering Huawei Cloud product knowledge, event updates, expert talks, and more. Together we continuously innovate to build the cloud foundation of an intelligent world.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.