QNAP: Fix login on Python3
Method b64encode from base64 library returns different values for Python 2 and 3. For Python 2 you get a string, but on Python 3 you get a bytes object, which when converted to a string using the six.text_type method will result in a string of the form "b'password'" instead of getting "password". This will result in posting a request with the wrong password and failing to authenticate. To fix this we only need to call the decode method on the result of b64encode, as it works for both string and bytes objects and will always return the string we want. Closes-Bug: #1837538 Change-Id: I181fefbc8cc3d3fdfc996f4367658ea59a51a9fc
This commit is contained in:
parent
3f3b7189db
commit
d5950b36d1
File diff suppressed because it is too large
Load Diff
|
@ -1231,23 +1231,16 @@ class QnapAPIExecutor(object):
|
|||
|
||||
def execute_login(self):
|
||||
"""Login and return sid."""
|
||||
params = OrderedDict()
|
||||
params['pwd'] = base64.b64encode(self.password.encode("utf-8"))
|
||||
params['serviceKey'] = '1'
|
||||
params['user'] = self.username
|
||||
|
||||
sanitized_params = OrderedDict()
|
||||
|
||||
for key in params:
|
||||
value = params[key]
|
||||
if value is not None:
|
||||
sanitized_params[key] = six.text_type(value)
|
||||
|
||||
sanitized_params = urllib.parse.urlencode(sanitized_params)
|
||||
params = OrderedDict(
|
||||
pwd=base64.b64encode(self.password.encode('utf-8')).decode(),
|
||||
serviceKey='1',
|
||||
user=self.username,
|
||||
)
|
||||
encoded_params = urllib.parse.urlencode(params)
|
||||
url = ('/cgi-bin/authLogin.cgi?')
|
||||
|
||||
res_details = self._execute_and_get_response_details(
|
||||
self.ip, url, sanitized_params)
|
||||
self.ip, url, encoded_params)
|
||||
root = ET.fromstring(res_details['data'])
|
||||
LOG.debug('execute_login data: %s', res_details['data'])
|
||||
session_id = root.find('authSid').text
|
||||
|
|
Loading…
Reference in New Issue