H. *_*ven 5 python connect attributeerror rethinkdb
我正在尝试为 RethinkDB API 制作一个包装模块,但在导入我的类(称为 rethinkdb.py)时遇到了 AttributeError。我在具有共享文件夹“Github”的虚拟机中工作。
我在 IPython 控制台中执行此操作:
import library.api.rethinkdb as re
Run Code Online (Sandbox Code Playgroud)
这是错误:
回溯(最近一次调用最后一次):
文件“”,第 1 行,在 import library.api.rethinkdb as re
文件“/media/sf_GitHub/library/api/rethinkdb.py”,第 51 行,在 conn = Connection().connect_to_database() 中
文件“/media/sf_GitHub/library/api/rethinkdb.py”,第48行,在connect_to_database raise e
AttributeError: 'module' 对象没有属性 '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()
Run Code Online (Sandbox Code Playgroud)
我今天遇到了类似的事情,我注意到作者在以后的版本中改变了 API 的基本行为。
从我在我的机器上测试过的:
v2.3.0
import rethinkdb as r
r.connect()
Run Code Online (Sandbox Code Playgroud)
v2.4.1
import rethinkdb as r
rdb = r.RethinkDB()
rdb.connect()
Run Code Online (Sandbox Code Playgroud)
当我跑步时它对我有用:
import rethinkdb as rdb
r = rdb.RethinkDB()
r.connect('localhost', 28015).repl()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1897 次 |
最近记录: |