无法理解来自clickhouse服务器的错误消息

mfuanj7w  于 2021-07-15  发布在  ClickHouse
关注(0)|答案(1)|浏览(551)

当我试图通过python套接字连接到clickhouse服务器时,收到以下消息:

received data:  b'\x02e\x00\x00\x00\x10DB::NetException/DB::NetException: Unexpected packet from client\xf8\x070. Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x104191d0 in /usr/bin/clickhouse\n1. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x8fff8ad in /usr/bin/clickhouse\n2. ? @ 0x91083e1 in /usr/bin/clickhouse\n3. DB::TCPHandler::runImpl() @ 0x9105bd7 in /usr/bin/clickhouse\n4. DB::TCPHandler::run() @ 0x9107650 in /usr/bin/clickhouse\n5. Poco::Net::TCPServerConnection::start() @ 0x10304f4b in /usr/bin/clickhouse\n6. Poco::Net::TCPServerDispatcher::run() @ 0x103053db in /usr/bin/clickhouse\n7. Poco::PooledThread::run() @ 0x104b2fa6 in /usr/bin/clickhouse\n8. Poco::ThreadImpl::runnableEntry(void*) @ 0x104ae260 in /usr/bin/clickhouse\n9. start_thread @ 0x76db in /lib/x86_64-linux-gnu/libpthread-2.27.so\n10. /build/glibc-OTsEL5/glibc-2.27/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:97: __clone'

这是我的python代码

TCP_IP = "localhost"
TCP_PORT = 9000
BUFFER_SIZE = 1024
MESSAGE = "--user default --password xxxxxxx".encode("utf-8")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c = s.connect_ex((TCP_IP, TCP_PORT))
print (c)
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()
print ("received data: ", data)

我认为这个错误来自发送到服务器的错误消息,但是当我在ubuntu终端输入相同的内容时,它没有错误。我该怎么修?

c86crjj0

c86crjj01#

它需要遵循clickhouse本机协议规范才能从服务器获得有效响应。
查看源代码以获取有关协议的更多详细信息:
数据包类型-协议.h
命令实现-hello、ping等。
对于python,存在支持clickhouse本机协议的clickhouse驱动程序包:
数据包类型-protocol.py
命令实现-hello、ping等。
我建议不要直接进行tcp请求,而是使用clickhouse驱动程序包。

相关问题