Skip to content

Commit 522da1d

Browse files
authored
fix(stt): Add access token support for web socket (#514)
1 parent 1edae76 commit 522da1d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

watson_developer_cloud/speech_to_text_v1.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
except ImportError:
7979
from urllib import urlencode
8080

81+
BEARER = 'Bearer'
8182
##############################################################################
8283
# Service
8384
##############################################################################
@@ -516,9 +517,13 @@ def recognize_with_websocket(self,
516517
if 'headers' in kwargs:
517518
headers.update(kwargs.get('headers'))
518519

519-
authstring = "{0}:{1}".format(self.username, self.password)
520-
base64_authorization = base64.b64encode(authstring.encode('utf-8')).decode('utf-8')
521-
headers['Authorization'] = 'Basic {0}'.format(base64_authorization)
520+
if self.token_manager:
521+
access_token = self.token_manager.get_token()
522+
headers['Authorization'] = '{0} {1}'.format(BEARER, access_token)
523+
else:
524+
authstring = "{0}:{1}".format(self.username, self.password)
525+
base64_authorization = base64.b64encode(authstring.encode('utf-8')).decode('utf-8')
526+
headers['Authorization'] = 'Basic {0}'.format(base64_authorization)
522527

523528
url = self.url.replace('https:', 'wss:')
524529
params = {

0 commit comments

Comments
 (0)