mymarilyn / clickhouse-driver

ClickHouse Python Driver with native interface support
https://clickhouse-driver.readthedocs.io
Other
1.2k stars 214 forks source link

Unable to Connect to ClickHouse Cloud Instance Using clickhouse_driver Python Package #415

Closed markusf1895 closed 7 months ago

markusf1895 commented 7 months ago

Describe the bug I am attempting to connect to my cloud instance using the clickhouse_driver package in Python.

When I use telnet XXXXXXXXXX.eu-central-1.aws.clickhouse.cloud 9440, I successfully establish a connection, receiving the following response:

Trying X.XXX.XXX.XXX...
Connected to XXXXXXXXXX.eu-central-1.aws.clickhouse.cloud.
Escape character is '^]'.

However, when I attempt to connect using the Python package I encounter the following error:

Failed to connect to clickhouse://cf6uw6mmnb.eu-central-1.aws.clickhouse.cloud:9440
Traceback (most recent call last):
  File "/Users/markus.sobotta/dev/pythonClickhouse/.venv/lib/python3.8/site-packages/clickhouse_driver/connection.py", line 395, in connect
    return self._init_connection(host, port)
  ...
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

To Reproduce Here my python code.

from clickhouse_driver import Client

client = Client(
  host='clickhouse://XXXXXXXXXX.eu-central-1.aws.clickhouse.cloud',
  port=9440,
  database='default',
  user='default',
  password='XXXXXXXXXXXXXXXXXXXX',
  connect_timeout=60000,
  secure=True,
)

query = "SELECT version()"
data = client.execute(query)

Expected behavior I expect the connection to be successfully established using the clickhouse_driver package as it was with telnet.

Actual Behavior Encountering a socket.gaierror indicating that the hostname or service name is not known.

Additional Notes Please let me know if there are any additional configurations or steps required to establish the connection successfully.

Versions Environment: Operating System: macOS Sonoma Version 14.3.1 Python Version: 3.8 ClickHouse Version: 24.0.2.54390 clickhouse-driver==0.2.5 Package Versions (requirements.txt):

backports.zoneinfo==0.2.1
certifi==2022.12.7
charset-normalizer==3.0.1
clickhouse-connect==0.5.0
clickhouse-driver==0.2.5
idna==3.4
lz4==4.3.2
pytz==2022.7.1
pytz-deprecation-shim==0.1.0.post0
requests==2.28.2
tzdata==2022.7
tzlocal==4.2
ujson==5.7.0
urllib3==1.26.14
zstandard==0.19.0
markusf1895 commented 7 months ago

The version seems to be the problem. Locally it works with image: clickhouse/clickhouse-server:23-alpine. Is there a way to get an older version in clickhouse cloud? Found SET compatibility = '23.12' on this page: https://clickhouse.com/docs/en/whats-new/changelog

xzkostyan commented 7 months ago

You should use Client(host='XXXXXXXXXX.eu-central-1.aws.clickhouse.cloud', or Client.from_url('clickhouse://XXXXXXXXXX.eu-central-1.aws.clickhouse.cloud'