问题描述
我在使用python的驱动程序连接到Windows docker容器中的Clickhouse时遇到问题.Clickhouse服务器在暴露于端口8123的Docker容器中的E驱动器上运行.我可以轻松地在R中使用此软件包连接 https://github.com/hannesmuehleisen/clickhouse-r 如此:
I am having an issue connecting to clickhouse in a windows docker container with python's driver. Clickhouse server is running on my E drive in a docker container exposed to port 8123. I can connect easily in R with this package https://github.com/hannesmuehleisen/clickhouse-r as so:
conn = DBI::dbConnect(clickhouse::clickhouse(),
host = "my_ip",
port = 8123L,
user = "myun",
password = "mypwd")
但是当我使用 https://clickhouse在python中尝试相同的操作时-driver.readthedocs.io/en/latest/quickstart.html 我遇到了一个问题:
But when I attempt the same thing in python using https://clickhouse-driver.readthedocs.io/en/latest/quickstart.html I run into an issue:
from clickhouse_driver import Client
client = Client(host = 'my_ip',
port = '8123',
user='myun',
password='mypwd',
secure=True,
verify=False,
database='db_name')
print(client.execute('SELECT now()'))
File "d:\ProgramData\Anaconda3\lib\site-packages\clickhouse_driver\connection.py", line 249, in connect
'{} ({})'.format(e.strerror, self.get_description())
NetworkError: Code: 210. [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:777) (my_ip:8123)
有人知道这个问题可能是什么吗?
Anyone know what the issue might be?
更新:
尝试安全= F并得到:
attempted secure = F and got:
File "d:\ProgramData\Anaconda3\lib\site-packages\clickhouse_driver\connection.py", line 243, in connect
'{} ({})'.format(e.strerror, self.get_description())
SocketTimeoutError: Code: 209. None
推荐答案
ClickHouse服务器与客户端之间的通信协议有两种:http(端口8123)和本机(端口9000).
There are two protocols for communication between ClickHouse server and clients: http (port 8123) and native (port 9000).
Http适用于curl/wget和其他工具.大多数ClickHouse客户端使用http进行数据传输.在您的情况下包括R.但是某些客户端使用本机协议(以及此python客户端).该协议应该比http更有效. https://clickhouse-driver.readthedocs.io/en/latest/#user-s-guide
Http is suitable for curl/wget and other tools. Most ClickHouse clients use http for data transfer. Including R in your case. But some clients use native protocol (go, and this python client). This protocol is supposed to be more efficient than http. https://clickhouse-driver.readthedocs.io/en/latest/#user-s-guide
从服务器容器中暴露端口9000,并在客户端中使用它.此端口也是此客户端中的默认端口.
Expose port 9000 from server container and use it in client. This port is also default in this client.
这篇关于使用Python驱动程序连接到Dockerized Clickhouse服务器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!