Encode username and password for basic auth

This is to ensure session creation also works if username and
password contain unicode characters.
Otherwise, python's requests will use latin-1 to encode these string.

Change-Id: Ia2a1c26cffe213d23cafcf5c33b6f82b8ef364e5
This commit is contained in:
Salvatore Orlando 2024-12-18 13:27:33 +00:00
parent c8a80f7e6f
commit e843f3a734
2 changed files with 5 additions and 2 deletions

View File

@ -74,7 +74,9 @@ class RequestsHTTPProviderTestCase(unittest.TestCase):
mock_api, cluster.Provider('9.8.7.6', 'https://9.8.7.6',
'nsxuser', password, None))
self.assertEqual(('nsxuser', password), session.auth)
self.assertEqual(('nsxuser'.encode('utf-8'),
password.encode('utf-8')),
session.auth)
self.assertFalse(session.verify)
self.assertIsNone(session.cert)
self.assertEqual(100,

View File

@ -214,7 +214,8 @@ class NSXRequestsHTTPProvider(AbstractHTTPProvider):
# Set the headers with Auth info when token provider is set,
# otherwise set the username and password
elif not config.token_provider:
session.auth = (provider.username, provider.password)
session.auth = (provider.username.encode('utf-8'),
provider.password.encode('utf-8'))
# NSX v3 doesn't use redirects
session.max_redirects = 0