RethinkDB 连接 AttributeError [英] RethinkDB connect AttributeError
问题描述
我正在尝试为 RethinkDB API 制作一个包装模块,但在导入我的类(称为 rethinkdb.py)时遇到了 AttributeError.我正在使用共享文件夹Github"的虚拟机工作.
I'm trying to make a wrapper module for the RethinkDB API and I've come across an AttributeError when importing my class(called rethinkdb.py). I'm working in a virtual machine having a shared folder 'Github'.
我在 IPython 控制台中执行此操作:
I do this in IPython console:
import library.api.rethinkdb as re
这是错误:
回溯(最近一次调用最后一次):
Traceback (most recent call last):
文件",第 1 行,在导入 library.api.rethinkdb as re
File "", line 1, in import library.api.rethinkdb as re
文件/media/sf_GitHub/library/api/rethinkdb.py",第 51 行,在conn = Connection().connect_to_database()
File "/media/sf_GitHub/library/api/rethinkdb.py", line 51, in conn = Connection().connect_to_database()
文件/media/sf_GitHub/library/api/rethinkdb.py",第 48 行,在connect_to_database提高e
File "/media/sf_GitHub/library/api/rethinkdb.py", line 48, in connect_to_database raise e
AttributeError: 'module' 对象没有属性 'connect'
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 的基本行为.
I ran into something similar today and I noticed the authors have changed basic behavior of the API in the later versions.
根据我在我的机器上测试过的:
From what I have tested on my machine:
v2.3.0
import rethinkdb as r
r.connect()
v2.4.1
import rethinkdb as r
rdb = r.RethinkDB()
rdb.connect()
这篇关于RethinkDB 连接 AttributeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!