From 804e3fea44139a64885f2e7bf179b7e24e28ac41 Mon Sep 17 00:00:00 2001 From: "Miguel A. Munoz" Date: Tue, 3 Sep 2019 17:09:07 +0200 Subject: [PATCH] Ensure full compatibility when ansible is install from Py2 --- lib/ansible/module_utils/network/fortios/fortios.py | 1 + lib/ansible/plugins/httpapi/fortios.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/network/fortios/fortios.py b/lib/ansible/module_utils/network/fortios/fortios.py index 56aee11f49f..7e1f1f19fda 100644 --- a/lib/ansible/module_utils/network/fortios/fortios.py +++ b/lib/ansible/module_utils/network/fortios/fortios.py @@ -33,6 +33,7 @@ import traceback from ansible.module_utils._text import to_native from ansible.module_utils.basic import env_fallback +from ansible.module_utils.basic import to_text import json diff --git a/lib/ansible/plugins/httpapi/fortios.py b/lib/ansible/plugins/httpapi/fortios.py index d1675bf88a7..14ef9a9c7a0 100644 --- a/lib/ansible/plugins/httpapi/fortios.py +++ b/lib/ansible/plugins/httpapi/fortios.py @@ -46,6 +46,7 @@ from ansible.module_utils.basic import to_text import urllib import json import re +import sys class HttpApi(HttpApiBase): @@ -65,7 +66,11 @@ class HttpApi(HttpApiBase): def login(self, username, password): """Call a defined login endpoint to receive an authentication token.""" - data = "username=" + urllib.parse.quote(username) + "&secretkey=" + urllib.parse.quote(password) + "&ajax=1" + if sys.version_info[0] >= 3: + data = "username=" + urllib.parse.quote(username) + "&secretkey=" + urllib.parse.quote(password) + "&ajax=1" + else: + data = "username=" + urllib.quote(username) + "&secretkey=" + urllib.quote(password) + "&ajax=1" + dummy, result_data = self.send_request(url='/logincheck', data=data, method='POST') if result_data[0] != '1': raise Exception('Wrong credentials. Please check')