【发布时间】:2020-10-21 01:49:08
【问题描述】:
已经为我的问题苦苦挣扎了一周,希望你能向我解释这里出了什么问题。
我正在尝试连接我在远程服务器上拥有的 Clickhouse DB,这是绝对默认设置。所以我要连接到远程服务器并在我的机器上创建一个隧道。
import sshtunnel as sshtunnel
from clickhouse_driver import connect
server = sshtunnel.SSHTunnelForwarder(
('host', 22),
ssh_username='username',
ssh_pkey="username.openssh",
ssh_private_key_password="password",
remote_bind_address=('localhost', 8123),
local_bind_address=('localhost', 555)
)
server.start()
conn = connect(host='localhost', port=555, database='ertb')
cursor = conn.cursor()
cursor.execute('SHOW TABLES')
cursor.fetchall()
server.stop()
我收到此错误
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/alerts/ssh_coonection.py", line 42, in <module>
cursor.execute('SHOW TABLES')
File "C:\Users\user\PycharmProjects\alerts\venv\lib\site-packages\clickhouse_driver\dbapi\cursor.py", line 102, in execute
**execute_kwargs
File "C:\Users\user\PycharmProjects\alerts\venv\lib\site-packages\clickhouse_driver\client.py", line 205, in execute
self.connection.force_connect()
File "C:\Users\user\PycharmProjects\alerts\venv\lib\site-packages\clickhouse_driver\connection.py", line 180, in force_connect
self.connect()
File "C:\Users\user\PycharmProjects\alerts\venv\lib\site-packages\clickhouse_driver\connection.py", line 256, in connect
return self._init_connection(host, port)
File "C:\Users\user\PycharmProjects\alerts\venv\lib\site-packages\clickhouse_driver\connection.py", line 237, in _init_connection
self.send_hello()
File "C:\Users\user\PycharmProjects\alerts\venv\lib\site-packages\clickhouse_driver\connection.py", line 325, in send_hello
write_binary_str(self.user, self.fout)
File "C:\Users\user\PycharmProjects\alerts\venv\lib\site-packages\clickhouse_driver\writer.py", line 19, in write_binary_str
text = text.encode('utf-8')
AttributeError: 'NoneType' object has no attribute 'encode'
我真的很想了解这个 NoneType 对象出现在哪里,但有点卡在代码中。
【问题讨论】:
-
但是 mymarilyn/clickhouse-driver 在端口 9000 上使用 tcp 协议而不是 http(8123)
-
谢谢,我已经使用了 9000 端口和 clickhouse_driver 客户端,所以一切都开始工作了
标签: python ssh ssh-tunnel clickhouse