From a51a699314f6b819f0eeab7a9e8c0f8cad29775a Mon Sep 17 00:00:00 2001 From: Tim Werner Date: Thu, 22 Mar 2018 22:38:01 +0100 Subject: [PATCH] make jira authentication Python3 compatible (#33862) * make jira authentication Python3 compatible --- lib/ansible/modules/web_infrastructure/jira.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/web_infrastructure/jira.py b/lib/ansible/modules/web_infrastructure/jira.py index 87014219129..9d84bb7ee5c 100644 --- a/lib/ansible/modules/web_infrastructure/jira.py +++ b/lib/ansible/modules/web_infrastructure/jira.py @@ -233,6 +233,7 @@ EXAMPLES = """ import base64 import json import sys +from ansible.module_utils._text import to_text, to_bytes from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url @@ -249,7 +250,8 @@ def request(url, user, passwd, timeout, data=None, method=None): # resulting in unexpected results. To work around this we manually # inject the basic-auth header up-front to ensure that JIRA treats # the requests as authorized for this user. - auth = base64.encodestring('%s:%s' % (user, passwd)).replace('\n', '') + auth = to_text(base64.b64encode(to_bytes('{0}:{1}'.format(user, passwd), errors='surrogate_or_strict'))) + response, info = fetch_url(module, url, data=data, method=method, timeout=timeout, headers={'Content-Type': 'application/json', 'Authorization': "Basic %s" % auth})