consulate
consulate copied to clipboard
AttributeError: 'bytes' object has no attribute 'get' when Consul in leaderless state
On Python 3.5.2 / consulate 0.6 I was seeing an intermittent error:
...
File "/app/__init__.py", line 65, in consul_lock
sid = consul.session.create(session_name, ttl=ttl)
File "/opt/conda/lib/python3.5/site-packages/consulate/api/session.py", line 67, in create
return self._put_response_body(['create'], None, payload).get('ID')
AttributeError: 'bytes' object has no attribute 'get'
After splicing in a debug print(self._put_response_body(['create'], None, payload)), it would tell me this:
*** DEBUG <class 'bytes'> : b'No cluster leader'.
This indicated problems with my consul setup, and I was able to simply restart all my instances as this is the only application they are currently used for. I'm not sure what the proper handling should be in this case, but something to handle the case where the response body isn't a dict seems needed.