Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RethinkDB connect AttributeError

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()
like image 633
H. Steven Avatar asked Nov 04 '15 08:11

H. Steven


2 Answers

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()
like image 95
amitection Avatar answered Nov 06 '22 11:11

amitection


It worked for me when I ran:

import rethinkdb as rdb
r = rdb.RethinkDB()
r.connect('localhost', 28015).repl()
like image 4
LeandroOrdonez Avatar answered Nov 06 '22 12:11

LeandroOrdonez