Tag Archives: ‘str’ object has no attribute ‘items’

[Solved] Python redis Sorted Set Error: ‘str’ object has no attribute ‘items’

redis.zadd('language', 'C', 1)

Add an element to the sorted set and report an error ‘STR’ object has no attribute ‘items’

Error source

        for pair in iteritems(mapping):
            pieces.append(pair[1])
            pieces.append(pair[0])

We need a dictionary here

Modification

redis.zadd('language', {'C': 1})

Done!