From 38b3c43c68ee0d83510861c0a46c0e30744b3f3d Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 24 Oct 2016 07:01:00 -0700 Subject: [PATCH] Fix uri for change in case in response In python3, response fields are title cased whereas in python2 they were not. We return these fields to the module's caller so we need to normalize all of them to be lower case. This reverts the lowercase check from 454f741ef5b56cccd123e12d7b2e6fe31d47c755 as that one was only targetted as a single field. --- lib/ansible/modules/network/basics/uri.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/network/basics/uri.py b/lib/ansible/modules/network/basics/uri.py index dfd8e14a953..d641d979013 100644 --- a/lib/ansible/modules/network/basics/uri.py +++ b/lib/ansible/modules/network/basics/uri.py @@ -437,9 +437,11 @@ def main(): # Transmogrify the headers, replacing '-' with '_', since variables dont # work with dashes. + # In python3, the headers are title cased. Lowercase them to be + # compatible with the python2 behaviour. uresp = {} for key, value in six.iteritems(resp): - ukey = key.replace("-", "_") + ukey = key.replace("-", "_").lower() uresp[ukey] = value try: @@ -449,14 +451,8 @@ def main(): # Default content_encoding to try content_encoding = 'utf-8' - content_type_key = None - for key in uresp: - # Py2: content_type; Py3: Content_type - if 'content_type' == key.lower(): - content_type_key = key - break - if content_type_key is not None: - content_type, params = cgi.parse_header(uresp[content_type_key]) + if 'content_type' in uresp: + content_type, params = cgi.parse_header(uresp['content_type']) if 'charset' in params: content_encoding = params['charset'] u_content = to_text(content, encoding=content_encoding)