Search code examples
pythonrethinkdb

How to fix rethinkdb connection refused problem?


I'm following this guide here https://github.com/flaree/Flare-Cogs/tree/master/dankmemer. I got to the import rethinkdb part but I get this error when running the r.connect('localhost', 28015).repl() command. Been searching yesterday for a fix but couldn't find one.

r.connect('localhost', 28015).repl()
Traceback (most recent call last):
  File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 349, in __init__
    self._socket = socket.create_connection((self.host, self.port), timeout)
  File "/usr/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/usr/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/venv/lib/python3.8/site-packages/rethinkdb/__init__.py", line 93, in connect
    return self.make_connection(self.connection_type, *args, **kwargs)
  File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 830, in make_connection
    return conn.reconnect(timeout=timeout)
  File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 696, in reconnect
    return self._instance.connect(timeout)
  File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 538, in connect
    self._socket = SocketWrapper(self, timeout)
  File "/root/venv/lib/python3.8/site-packages/rethinkdb/net.py", line 437, in __init__
    raise ReqlDriverError(
rethinkdb.errors.ReqlDriverError: Could not connect to localhost:28015. Error: [Errno 111] Connection refused```


Solution

  • You need to run rethinkdb first. Enter your venv, and run tmux. Then run rethinkdb inside your tmux shell. This starts the rethinkdb server, and keeps it running. Close the SSH session, and open another one. Try running your code again.