0

Overview Enable to use IBM Watson API with Python. I keep getting 403 error (forbidden) no matter which URL I used I tried the following URLs:

But none of them work.

Code sample
import json
from os.path import join, dirname
from ibm_watson import TextToSpeechV1
from ibm_watson.websocket import SynthesizeCallback
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_watson import ApiException

apikey = 'XXXXXXXXXXXXXX'
url = 'https://stream.watsonplatform.net/text-to-speech/api'
try:
    authenticator = IAMAuthenticator(apikey)
    service = TextToSpeechV1(authenticator=authenticator)
    service.set_service_url(url)

    voices = service.list_voices().get_result()
    print(json.dumps(voices, indent=2))
except ApiException as ex:
    print("Method failed with status code " + str(ex.code) + ": " + ex.message)


I'm able to use the API via CURL.

Expected behavior Getting a success response from the API

Actual behavior Getting 403 (forbidden)

Screenshots image

SDK Version Latest

Additional information:

  • OS: Windows 10
  • Python 3.9.1
Amaynut
  • 4,091
  • 6
  • 39
  • 44

1 Answers1

0

As per the API documentation ( https://cloud.ibm.com/apidocs/text-to-speech?code=python#authentication ), it should be:

url = 'https://api.us-east.text-to-speech.watson.cloud.ibm.com'
chughts
  • 4,210
  • 2
  • 14
  • 27