python连接Phoenix

痴心易碎 提交于 2020-01-19 11:40:52

1、启动Phoenix监听端口

#启动,端口:8765
[root@node1 ~]# /opt/phoenix-4.11.0/bin/queryserver.py start
starting Query Server, logging to /tmp/phoenix/root-queryserver.log

[root@node1 ~]# netstat -ntlp |grep 8765
tcp6       0      0 :::8765                 :::*                    LISTEN      50094/java


2、phoenixdb

安装包

#phoenixdb包的版本要和phoenix对应,参考官网:
https://python-phoenixdb.readthedocs.io/en/latest/versions.html#version-0-7
#我的Phoenix是4.11,所以要安装0.7版本
>pip3 install phoenixdb==0.7


python脚本:

#!/usr/bin/env python
# encoding: utf-8

"""
@author:  'Administrator'
@contact:  
@time: 
"""
import phoenixdb
import phoenixdb.cursor


database_url = 'http://node1:8765/'
conn = phoenixdb.connect(database_url, autocommit=True)

cursor = conn.cursor()
cursor.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username VARCHAR)")
cursor.execute("UPSERT INTO users VALUES (?, ?)", (1, 'admin'))
cursor.execute("SELECT * FROM users")
print(cursor.fetchall())


但是我的脚本执行后,会报错,如下:

因为初学乍练,没有解决掉,希望知道解决办法的朋友给我留个言,多谢

Traceback (most recent call last):
  File "D:/pycharm2018/oldboy-code/day58/test/phoenixdemo.py", line 23, in <module>
    conn = phoenixdb.connect(database_url, autocommit=True)
  File "D:\python36\lib\site-packages\phoenixdb\__init__.py", line 67, in connect
    return Connection(client, **kwargs)
  File "D:\python36\lib\site-packages\phoenixdb\connection.py", line 56, in __init__
    self.open()
  File "D:\python36\lib\site-packages\phoenixdb\connection.py", line 73, in open
    self._client.open_connection(self._id, info=self._connection_args)
  File "D:\python36\lib\site-packages\phoenixdb\avatica.py", line 329, in open_connection
    response_data = self._apply(request)
  File "D:\python36\lib\site-packages\phoenixdb\avatica.py", line 216, in _apply
    parse_error_protobuf(response_body)
  File "D:\python36\lib\site-packages\phoenixdb\avatica.py", line 127, in parse_error_protobuf
    parse_and_raise_sql_error(err.error_message)
  File "D:\python36\lib\site-packages\phoenixdb\avatica.py", line 108, in parse_and_raise_sql_error
    raise_sql_error(int(code), sqlstate, message)
  File "D:\python36\lib\site-packages\phoenixdb\avatica.py", line 101, in raise_sql_error
    raise error_class(message, code, sqlstate)
phoenixdb.errors.OperationalError: ('Malformed connection url. :node1:2181,node2:2181,node3:2181:2181:/hbase;', 102, '08001', None)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!