gpt4 book ai didi

python - RethinkDB 连接属性错误

转载 作者:太空狗 更新时间:2023-10-30 02:58:36 25 4
gpt4 key购买 nike

我正在尝试为 RethinkDB API 制作一个包装器模块,但在导入我的类(称为 rethinkdb.py)时遇到了 AttributeError。我在具有共享文件夹“Github”的虚拟机中工作。

我在 IPython 控制台中这样做:

import library.api.rethinkdb as re

这是错误:

Traceback (most recent call last):

File "", line 1, in import library.api.rethinkdb as re

File "/media/sf_GitHub/library/api/rethinkdb.py", line 51, in conn = Connection().connect_to_database()

File "/media/sf_GitHub/library/api/rethinkdb.py", line 48, in connect_to_database raise e

AttributeError: 'module' object has no attribute 'connect'

这是代码:

import rethinkdb as r  #The downloaded RethinkDB module from http://rethinkdb.com/

class Connection(object):
def __init__(self, host='127.0.0.1', port=28015, database=None, authentication_key=''):
self.host = host
self.port = port
if database is None:
self.db = 'test'
self.auth_key = authentication_key

def connect_to_database(self):
try:
conn = r.connect(self.host, self.port, self.db, self.auth_key)
except Exception, e:
raise e
return conn

conn = Connection().connect_to_database()

最佳答案

我今天遇到了类似的事情,我注意到作者在后来的版本中改变了 API 的基本行为。

根据我在我的机器上测试过的内容:

v2.3.0

import rethinkdb as r
r.connect()

v2.4.1

import rethinkdb as r
rdb = r.RethinkDB()
rdb.connect()

关于python - RethinkDB 连接属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33516546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com