Skip to content

Commit 1b0c1ab

Browse files
committed
fix(recognize): Update websocket request
1 parent 55e9ae5 commit 1b0c1ab

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

ibm_watson/speech_to_text_v1_adapter.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,20 @@ def recognize_using_websocket(self,
207207
raise Exception(
208208
'Callback is not a derived class of RecognizeCallback')
209209

210+
request = {}
211+
210212
headers = {}
211213
if self.default_headers is not None:
212214
headers = self.default_headers.copy()
213215
if 'headers' in kwargs:
214216
headers.update(kwargs.get('headers'))
217+
request['headers'] = headers
215218

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

224222
url = self.url.replace('https:', 'wss:')
223+
225224
params = {
226225
'model': model,
227226
'customization_id': customization_id,
@@ -232,6 +231,7 @@ def recognize_using_websocket(self,
232231
}
233232
params = dict([(k, v) for k, v in params.items() if v is not None])
234233
url += '/v1/recognize?{0}'.format(urlencode(params))
234+
request['url'] = url
235235

236236
options = {
237237
'content_type': content_type,
@@ -253,12 +253,13 @@ def recognize_using_websocket(self,
253253
'audio_metrics': audio_metrics
254254
}
255255
options = dict([(k, v) for k, v in options.items() if v is not None])
256+
request['options'] = options
256257

257258
RecognizeListener(audio,
258-
options,
259+
request.get('options'),
259260
recognize_callback,
260-
url,
261-
headers,
261+
request.get('url'),
262+
request.get('headers'),
262263
http_proxy_host,
263264
http_proxy_port,
264-
self.verify)
265+
self.disable_ssl_verification)

0 commit comments

Comments
 (0)