Ensure full compatibility when ansible is install from Py2

pull/61691/head
Miguel A. Munoz 5 years ago
parent b92c860d32
commit 804e3fea44

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

@ -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."""
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')

Loading…
Cancel
Save