Grokzen / redis-py-cluster

Python cluster client for the official redis cluster. Redis 3.0+.
https://redis-py-cluster.readthedocs.io/
MIT License
1.1k stars 315 forks source link

ImportError: cannot import name 'SlotNotCoveredError' from 'rediscluster.exceptions' #509

Closed iDataist closed 1 year ago

iDataist commented 1 year ago

Versions: python==3.8.12 redis-py-cluster==2.1.3 redis==3.5.3

Python script:

from rediscluster import RedisCluster
import logging

logging.basicConfig(level=logging.INFO)
redis = RedisCluster(startup_nodes=[{"host": "xxx.yyy.clustercfg.zzz1.cache.amazonaws.com","port": "6379"}], decode_responses=True,skip_full_coverage_check=True)

if redis.ping():
    logging.info("Connected to Redis")

Error:

ImportError                               Traceback (most recent call last)
/tmp/ipykernel_8807/488903058.py in <cell line: 1>()
----> 1 from rediscluster import RedisCluster
      2 import logging
      3 
      4 logging.basicConfig(level=logging.INFO)
      5 redis = RedisCluster(startup_nodes=[{"host": "xxx.yyy.clustercfg.zzz1.cache.amazonaws.com","port": "6379"}], decode_responses=True,skip_full_coverage_check=True)

~/anaconda3/envs/python3/lib/python3.8/site-packages/rediscluster/__init__.py in <module>
      5 
      6 # rediscluster imports
----> 7 from rediscluster.client import RedisCluster
      8 from rediscluster.connection import (
      9     ClusterBlockingConnectionPool,

~/anaconda3/envs/python3/lib/python3.8/site-packages/rediscluster/client.py in <module>
     10 
     11 # rediscluster imports
---> 12 from .connection import (
     13     ClusterConnection,
     14     ClusterConnectionPool,

~/anaconda3/envs/python3/lib/python3.8/site-packages/rediscluster/connection.py in <module>
     13 # rediscluster imports
     14 from .nodemanager import NodeManager
---> 15 from .exceptions import (
     16     RedisClusterException, AskError, MovedError,
     17     TryAgainError, ClusterDownError, ClusterCrossSlotError,

ImportError: cannot import name 'SlotNotCoveredError' from 'rediscluster.exceptions' (/home/ec2-user/anaconda3/envs/python3/lib/python3.8/site-packages/rediscluster/exceptions.py)

Please recommend a combination of python, redis, redis-py-cluster versions that allow me to import rediscluster.

Grokzen commented 1 year ago

@iDataist I have no idea how you get to this state. The code is there in the release and things works out on my end if i attempt to use redis-py-cluster at all as these errors is imported one by one when you run your basic usage example. There seems to be a local issue in your environment that somehow screws up your code. If you manually inspects the exceptions.py file that it claims do not have this code, you should either see this exception or find nothing at all. My usual recommendation when you get to these things is to just wipe your local dev environment, throw away any other application that you tried to use to install that local dev env and fall back to use plain old virtualenv, virtualenvwrapper & pip to build and install the dev env from scratch and usually that sorts out these kinds of things.