How to handle "Redis.exceptions.ConnectionError: Connection has data"
How to handle "Redis.exceptions.ConnectionError: Connection has data"
我收到以下输出:
Traceback (most recent call last):
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/connection.py", line 1192, in get_connection
raise ConnectionError('Connection has data')
redis.exceptions.ConnectionError: Connection has data
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/hubs/hub.py", line 457, in fire_timers
timer()
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/hubs/timer.py", line 58, in __call__
cb(*args, **kw)
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/greenthread.py", line 214, in main
result = function(*args, **kwargs)
File "crawler.py", line 53, in fetch_listing
url = dequeue_url()
File "/home/ec2-user/WebCrawler/helpers.py", line 109, in dequeue_url
return redis.spop("listing_url_queue")
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/client.py", line 2255, in spop
return self.execute_command('SPOP', name, *args)
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/client.py", line 875, in execute_command
conn = self.connection or pool.get_connection(command_name, **options)
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/connection.py", line 1197, in get_connection
raise ConnectionError('Connection not ready')
redis.exceptions.ConnectionError: Connection not ready
我找不到与此特定错误相关的任何问题。我emptied/flushed都是redis数据库,应该没有数据吧。我认为它与 eventlet
和修补有关。但是即使我将以下代码放在文件的开头,也会出现错误。
import eventlet
eventlet.monkey_path()
这个错误是什么意思?
终于,我找到了问题的答案。
使用python连接redis时,我指定了编号为0
的数据库。
redis = redis.Redis(host=example.com, port=6379, db=0)
将数据库更改为数字 1
后,它起作用了。
redis = redis.Redis(host=example.com, port=6379, db=1)
另一种方法是在etc\redis\redis.conf
中将protected_mode
设置为无。 运行本地redis时推荐。
我收到以下输出:
Traceback (most recent call last):
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/connection.py", line 1192, in get_connection
raise ConnectionError('Connection has data')
redis.exceptions.ConnectionError: Connection has data
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/hubs/hub.py", line 457, in fire_timers
timer()
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/hubs/timer.py", line 58, in __call__
cb(*args, **kw)
File "/home/ec2-user/env/lib64/python3.7/site-packages/eventlet/greenthread.py", line 214, in main
result = function(*args, **kwargs)
File "crawler.py", line 53, in fetch_listing
url = dequeue_url()
File "/home/ec2-user/WebCrawler/helpers.py", line 109, in dequeue_url
return redis.spop("listing_url_queue")
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/client.py", line 2255, in spop
return self.execute_command('SPOP', name, *args)
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/client.py", line 875, in execute_command
conn = self.connection or pool.get_connection(command_name, **options)
File "/home/ec2-user/env/lib64/python3.7/site-packages/redis/connection.py", line 1197, in get_connection
raise ConnectionError('Connection not ready')
redis.exceptions.ConnectionError: Connection not ready
我找不到与此特定错误相关的任何问题。我emptied/flushed都是redis数据库,应该没有数据吧。我认为它与 eventlet
和修补有关。但是即使我将以下代码放在文件的开头,也会出现错误。
import eventlet
eventlet.monkey_path()
这个错误是什么意思?
终于,我找到了问题的答案。
使用python连接redis时,我指定了编号为0
的数据库。
redis = redis.Redis(host=example.com, port=6379, db=0)
将数据库更改为数字 1
后,它起作用了。
redis = redis.Redis(host=example.com, port=6379, db=1)
另一种方法是在etc\redis\redis.conf
中将protected_mode
设置为无。 运行本地redis时推荐。