Good Afternoon,
I am using pythomnic3k python framework and sharded solr, redis database servers.
Following is my api request:
http://1.2.3.4:8090/api20/account2/addnewemail?Email=foo@yahoo.com&Token=[redacted]&AccountID=[redacted]
error:
AttributeError: 'function' object has no attribute 'get'
Function where this error arises:
def count_maps(r): dt = r.get(Namespace.MAPPINGS + ':count')
r is redis instance and
Namespance.Mappings + ':count' = ytk:map:count
solr schema xml file has these sharded instance:
<?xml version="1.0" encoding="UTF-8"?> <mapping> <meta> <date>201-12-13 00:00:00</date> <active>true</active> <static url="0.0.0.0:8983/solr" /> </meta> <map> <shard url="0.0.0.0:8983/solr" start="00000000" end="00009999" readonly="false"> <slave url="0.0.0.0:8983/solr" /> </shard> </map> </mapping>
Redis instance r is in redis_utils.py
def test_redis_obj(r): try: r.ping() return True except ConnectionError: return False def redis_obj(redis_def, timeout = None): if not redis_def: return None return redis.StrictRedis( host = redis_def["ip"], port = redis_def["port"], db = redis_def["db"], socket_timeout = timeout ) def random_redis_obj(timeout = None): return redis_obj(random_redis_def(), timeout) def random_tested_redis_obj(attempts = 3, timeout = 1): for _ in range(attempts): r = random_redis_obj(timeout) if r and test_redis_obj(r): return r raise YtkRedisError("active redis server not found (%d attempts done)" % attempts)
Here is function where
count_maps(r)
is called in solr_manager.py:def get_unique_shards(r, the_map: int = -1): ''' Returns array: [map][shard](0: url; 1: [slaves urls]) with unique shards with their slaves in mappings ''' num = count_maps(r) if the_map >= num: raise IndexError("There aren't map at index " + str(the_map)) if the_map < 0: return _get_all_unique_shards(r, num) else: return _get_unique_shards(r, the_map) def count_maps(r): dt = r.get(Namespace.MAPPING + ':count') if dt is not None: return int(dt) return None
I understand this redis object try to count solr instances, is it right ?
Kindly help me in what can be possible reason why my redis object is None ? I checked my logs same 'get attribute..' error and unable to debug it.