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
This commit is contained in:
Corey Bryant 2015-12-16 10:27:25 -05:00
parent 84f61b58f9
commit 87d8ab5b88
1 changed files with 1 additions and 1 deletions

View File

@ -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