redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

137 篇文章 13 订阅
40 篇文章 0 订阅
$ pip install redis
>>> import redis
>>> conn = redis.Redis()
>>> conn.keys('*')
Traceback (most recent call last):
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
    sock = self._connect()
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 541, in _connect
    raise err
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 529, in _connect
    sock.connect(socket_address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/henry/.local/lib/python3.5/site-packages/redis/client.py", line 667, in execute_command
    connection.send_command(*args)
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
    self.connect()
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
    sock = self._connect()
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 541, in _connect
    raise err
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 529, in _connect
    sock.connect(socket_address)
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 "/home/henry/.local/lib/python3.5/site-packages/redis/client.py", line 1032, in keys
    return self.execute_command('KEYS', pattern)
  File "/home/henry/.local/lib/python3.5/site-packages/redis/client.py", line 673, in execute_command
    connection.send_command(*args)
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
    self.connect()
  File "/home/henry/.local/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

这个问题是因为没安装Redis服务器造成的。
解决办法:

sudo apt-get install redis-server

参考文献:
1. Rescue : Connection refused - Unable to connect to Redis on localhost:6379

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值