下午好,AttributeError的: '功能' 对象有没有属性 '得到'
我使用pythomnic3k蟒蛇框架和碎片化的Solr,Redis的数据库服务器。
以下是我的API请求:
http://1.2.3.4:8090/api20/account2/[email protected]&Token=[redacted]&AccountID=[redacted]
错误:
AttributeError: 'function' object has no attribute 'get'
函数,其中这个错误出现了:
def count_maps(r): dt = r.get(Namespace.MAPPINGS + ':count')
r是Redis的实例,并
Namespance.Mappings + ':count' = ytk:map:count
Solr模式XML文件,这些碎片化的实例:
<?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的情况下,r是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)
下面是函数,其中
count_maps(r)
被称为在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
我明白这个redis对象尝试计算solr实例,是不是?
请帮助我为什么我的redis对象是None可能的原因?我检查了我的日志相同'get属性..'错误,无法调试它。
'r'不是'None';根据你的错误,这是一个功能。请在创建'r'的地方发布代码。 – jonrsharpe
@jonrsharpe我已经更新了我的问题,其中声明了r的代码, – JKV
不,您已经发布了一些代码,它返回一个名为'r'的对象。不调用'count_maps'。顺便说一句 - 这真的是你的空白? – doctorlove