From 87d8ab5b88c7ec37ec525a3f4d2b647959a9efcf Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 16 Dec 2015 10:27:25 -0500 Subject: [PATCH] Iterate over copy of session.adapters keys in Python2/3 Iterate over a copy of session.adapters keys in both Python 2.x and Python 3.x. In Python 3.5+, keys() is not a copy, and therefore items can't be popped from it while iterating. RuntimeError: OrderedDict mutated during iteration https://bugs.python.org/issue24369 https://hg.python.org/cpython/rev/0d8679858272 Change-Id: I038f1e8261fa6b29401e6c64db95f7480b35a598 Closes-Bug: #1502232 --- keystoneauth1/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keystoneauth1/session.py b/keystoneauth1/session.py index 3de4fc8c..b725c3c8 100644 --- a/keystoneauth1/session.py +++ b/keystoneauth1/session.py @@ -52,7 +52,7 @@ def _construct_session(session_obj=None): if not session_obj: session_obj = requests.Session() # Use TCPKeepAliveAdapter to fix bug 1323862 - for scheme in session_obj.adapters.keys(): + for scheme in list(session_obj.adapters): session_obj.mount(scheme, TCPKeepAliveAdapter()) return session_obj