简体   繁体   中英

Python redis get method raises an AttributeError for non existing key

I have the following part of code:

rd = redis.Redis(host, port, db, password, socket_timeout, connection_pool, charset, errors, unix_socket_path)

check_flag = rd.get("some_key") if check_flag is not None: do_something()

But get method of Redis raises an AttributeError: AttributeError: 'str' object has no attribute 'iteritems'

I'm not sure if it's OK to share full text of traceback here.

I'm using redis 2.10.5

Do somebody have any ideas what is going on?

PS I was looking through stackoverflow for the same issues, but with no success

UPD: Added full traceback

init_flag = self.redis.get("face_init") File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 880, in get return self.execute_command('GET', name) File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 572, in execute_command connection.send_command(*args) File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 563, in send_command self.send_packed_command(self.pack_command(*args)) File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 538, in send_packed_command self.connect() File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 439, in connect sock = self._connect() File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 475, in _connect for k, v in iteritems(self.socket_keepalive_options): File "/usr/local/lib/python2.7/dist-packages/redis/_compat.py", line 27, in iteritems return x.iteritems() AttributeError: 'str' object has no attribute 'iteritems'

Looks like you might have found a bug in the redis-py library.

I'd first try updating to the newest version of the library, as well as trying out other releases, and see if you see any different behaviour. You should be able to checkout any given release of it from here, https://github.com/andymccurdy/redis-py , and then use the command listed here to do a local install of the checked out code.

You might also want to try under a few different network conditions. That code path in the trace looks like it's related to sending the packets to the Redis Server, so it might be worth testing what happens when you're not connecting to a valid server address.

You could also run the Redis Monitor command from the redis cli, to see if anything is making it to the server or not.

If you still don't see any thing obviously wrong with those additional bits of trouble shooting, I'd open up an issue on the Redis-py github repo, and see if they can help track down the underlying issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM