广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python连接clickhouse的端口问题及解决
  • 248
分享到

python连接clickhouse的端口问题及解决

2024-04-02 19:04:59 248人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

目录python连接clickhouse端口问题向clickhouse导数据报错Python连接clickhouse端口问题 <!-- It is the name th

Python连接clickhouse端口问题

   <!-- It is the name that will be shown in the clickhouse-client.
         By default, anything with "production" will be highlighted in red in query prompt.
    -->
    <!--display_name>production</display_name-->

    <!-- Port for Http api. See also 'https_port' for secure connections.
         This interface is also used by ODBC and JDBC drivers (DataGrip, Dbeaver, ...)
         and by most of WEB interfaces (embedded UI, Grafana, Redash, ...).
      -->
    <http_port>8123</http_port>

    <!-- Port for interaction by native protocol with:
         - clickhouse-client and other native ClickHouse tools (clickhouse-benchmark, clickhouse-copier);
         - clickhouse-server with other clickhouse-servers for distributed query processing;
         - ClickHouse drivers and applications supporting native protocol
         (this protocol is also infORMally called as "the tcp protocol");
         See also 'tcp_port_secure' for secure connections.
    -->
    <tcp_port>9000</tcp_port>

注意到可以使用两个端口,8123 和 9000 分别接收 http 协议和tcp协议。

  • 如果用jdbc连接,端口为 8123
  • 如果用driver连接,端口为 9000
from clickhouse_driver import Client
client = Client(host=host, port=port, user=user, passWord=password, database='default')
client  = get_client()
client.execute("show tables;")
print(client.execute("select * from test_arr"))
client.disconnect()

此时如果用8123端口则会得到如下报错:

clickhouse_driver.errors.UnexpectedPacketFromServerError: Code: 102. Unexpected packet from server 192.168.137.101:8123 (expected Hello or Exception, Got Unknown packet)

向clickhouse导数据报错

clickhouse_driver.errors.UnexpectedPacketFromServerError: Code: 102

今天用python写个etl从Mysql向clickhouse同步数据, 数据量不到1千万,导了一会报上面的第错误。然后在网上查了一下:找到文档写得很清楚:

Welcome to clickhouse-driver — clickhouse-driver 0.2.4 documentation

原来clickhouse提供两个端口:8123和9000

用native protocal需要使用9000端口,然后修改端口后成功。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: python连接clickhouse的端口问题及解决

本文链接: https://www.lsjlt.com/news/118084.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作