python连接clickhouse,UnexpectedPacketFromServerError: Code: 102

安装驱动

pip install clickhouse-driver

本地环境

python Python 3.8.8
clickhouse-driver 0.2.8
clickhouse server 20.3

https://github.com/mymarilyn/clickhouse-driver
https://clickhouse-driver.readthedocs.io/en/latest/installation.html

from clickhouse_driver import Client

ck = Client(
	user=clickhouse_config['user'], 
	password=clickhouse_config['password'],
    host=clickhouse_config['host'], port=clickhouse_config['port'], 
    database=clickhouse_config['database']
)

sql = "SELECT id,author,publisher,title,summary FROM bigdata.dw_dim_metadata_book_cip_all WHERE `title` = '互联网' limit 1"
res = ck.execute(sql)  # list

这里特别要注意的一点是端口问题,HTTP协议(默认端口8123);TCP (Native)协议(默认端口号为9000),Python里的clickhouse_driver用的TCP端口9000,DBeaver使用的是HTTP端口。

如果端口错误包报错:UnexpectedPacketFromServerError: Code: 102. Unexpected packet from server 220.202.33.52:19100 (expected Hello or Exception, got Unknown packet)

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值