Skip to content

Commit 6919730

Browse files
committed
Make sure that encodestring receives bytes as well as that we decode the bytes object returned
1 parent caddc4f commit 6919730

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

swiftype/swiftype.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,9 @@ def _request(self, method, path, params={}, data={}):
218218
headers = {}
219219
headers['User-Agent'] = USER_AGENT
220220
headers['Content-Type'] = 'application/json'
221-
222221
if self.__username is not None and self.__password is not None:
223222
credentials = "%s:%s" % (self.__username, self.__password)
224-
base64_credentials = base64.encodestring(credentials)
223+
base64_credentials = base64.encodestring(credentials.encode('utf-8')).decode()
225224
authorization = "Basic %s" % base64_credentials[:-1]
226225
headers['Authorization'] = authorization
227226
elif self.__access_token is not None and self.__api_key is None:

tests/test_swiftype.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,23 @@ def __create_temporary_engine(self, name = None):
287287
name = name if name else self.__time_name()
288288
return
289289

290+
291+
class TestClientUsernameAndPassword(unittest.TestCase):
292+
293+
def setUp(self):
294+
self.client = swiftype.Client(
295+
username='some_user',
296+
password='some_pasword',
297+
host='localhost:3000'
298+
)
299+
300+
def test_engine_create(self):
301+
with vcr.use_cassette('fixtures/engine_create.yaml'):
302+
engine = 'myengine'
303+
slug = self.client.create_engine(engine)['body']['slug']
304+
self.assertEqual(slug, engine)
305+
306+
290307
class TestPlatformUsers(unittest.TestCase):
291308

292309
def setUp(self):

0 commit comments

Comments
 (0)