Skip to content

Commit

Permalink
fix(recognize): Update websocket request
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdsouza committed Aug 29, 2019
1 parent 55e9ae5 commit 1b0c1ab
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ibm_watson/speech_to_text_v1_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,20 @@ def recognize_using_websocket(self,
raise Exception(
'Callback is not a derived class of RecognizeCallback')

request = {}

headers = {}
if self.default_headers is not None:
headers = self.default_headers.copy()
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
request['headers'] = headers

if self.token_manager:
access_token = self.token_manager.get_token()
headers['Authorization'] = '{0} {1}'.format(BEARER, access_token)
else:
authstring = "{0}:{1}".format(self.username, self.password)
base64_authorization = base64.b64encode(authstring.encode('utf-8')).decode('utf-8')
headers['Authorization'] = 'Basic {0}'.format(base64_authorization)
if self.authenticator:
self.authenticator.authenticate(request)

url = self.url.replace('https:', 'wss:')

params = {
'model': model,
'customization_id': customization_id,
Expand All @@ -232,6 +231,7 @@ def recognize_using_websocket(self,
}
params = dict([(k, v) for k, v in params.items() if v is not None])
url += '/v1/recognize?{0}'.format(urlencode(params))
request['url'] = url

options = {
'content_type': content_type,
Expand All @@ -253,12 +253,13 @@ def recognize_using_websocket(self,
'audio_metrics': audio_metrics
}
options = dict([(k, v) for k, v in options.items() if v is not None])
request['options'] = options

RecognizeListener(audio,
options,
request.get('options'),
recognize_callback,
url,
headers,
request.get('url'),
request.get('headers'),
http_proxy_host,
http_proxy_port,
self.verify)
self.disable_ssl_verification)

0 comments on commit 1b0c1ab

Please sign in to comment.