Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions test/integration/test_discovery_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Discoveryv1(TestCase):
def setUp(self):
self.discovery = watson_developer_cloud.DiscoveryV1(
version='2017-10-16',
username=os.getenv('DISCOVERY_TO_TEXT_USERNAME'),
password=os.getenv('DISCOVERY_TO_TEXT_PASSWORD'))
username="YOUR SERVICE USERNAME",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be os.getenv('DISCOVERY_USERNAME')

password="YOUR SERVICE PASSWORD")
self.discovery.set_default_headers({
'X-Watson-Learning-Opt-Out': '1',
'X-Watson-Test': '1'
Expand Down Expand Up @@ -84,7 +84,10 @@ def test_documents(self):
self.environment_id, self.collection_id, add_doc['document_id'])
assert doc_status is not None

with open(os.path.join(os.path.dirname(__file__), '../../resources/simple.html'), 'r') as fileinfo:
with open(
os.path.join(
os.path.dirname(__file__), '../../resources/simple.html'),
'r') as fileinfo:
update_doc = self.discovery.update_document(
self.environment_id,
self.collection_id,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_speech_to_text_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class TestSpeechToTextV1(TestCase):
def setUp(self):
self.speech_to_text = watson_developer_cloud.SpeechToTextV1(
username=os.getenv('SPEECH_TO_TEXT_USERNAME'),
password=os.getenv('SPEECH_TO_TEXT_PASSWORD'))
username=os.getenv('YOUR SERVICE USERNAME'),
password=os.getenv('YOUR SERVICE PASSWORD'))
self.speech_to_text.set_default_headers({
'X-Watson-Learning-Opt-Out':
'1',
Expand Down
3 changes: 2 additions & 1 deletion test/integration/test_text_to_speech_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

class TestIntegrationTextToSpeechV1(unittest.TestCase):
def setUp(self):
self.text_to_speech = watson_developer_cloud.TextToSpeechV1()
self.text_to_speech = watson_developer_cloud.TextToSpeechV1(
username="YOUR SERVICE USERNAME", password="YOUR SERVICE PASSWORD")
self.text_to_speech.set_default_headers({
'X-Watson-Learning-Opt-Out':
'1',
Expand Down
12 changes: 8 additions & 4 deletions watson_developer_cloud/speech_to_text_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
from .utils import deprecated
from watson_developer_cloud.websocket import RecognizeCallback, RecognizeListener
import base64
import urllib
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode

##############################################################################
# Service
Expand Down Expand Up @@ -241,8 +244,9 @@ def recognize_with_websocket(self,
headers = {}
if self.default_headers is not None:
headers = self.default_headers.copy()
base64_authorization = base64.b64encode(
self.username + ':' + self.password)

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)

url = self.url.replace('https:', 'wss:')
Expand All @@ -254,7 +258,7 @@ def recognize_with_websocket(self,
'version': version
}
params = _remove_null_values(params)
url = url + '/v1/recognize?{0}'.format(urllib.urlencode(params))
url = url + '/v1/recognize?{0}'.format(urlencode(params))

options = {
'content_type': content_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def build_start_message(self, options):
return options

def build_close_message(self):
return json.dumps({'action': 'close'})
return json.dumps({'action': 'close'}).encode('utf8')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for the error in python 3.6.4:

24, in onMessage
    self.sendMessage(self.build_close_message())
  File "/Users/erikadsouza/anaconda3/envs/python-3.6.4/lib/python3.6/site-packages/autobahn/websocket/protocol.py", line 2164, in sendMessage
    assert(type(payload) == bytes)
builtins.AssertionError:


# helper method that sends a chunk of audio if needed (as required what the specified pacing is)
def send_audio(self, data):
Expand Down