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'.
I do this in IPython console:
import library.api.rethinkdb as re
This is the error:
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'
This is the code:
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()
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()
It worked for me when I ran:
import rethinkdb as rdb
r = rdb.RethinkDB()
r.connect('localhost', 28015).repl()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With