watson-developer-cloud / python-sdk

:snake: Client library to use the IBM Watson services in Python and available in pip as watson-developer-cloud
https://pypi.org/project/ibm-watson/
Apache License 2.0
1.45k stars 828 forks source link

Text-to-speech API: Method failed with status code 403: Forbidden #777

Closed amaynut closed 3 years ago

amaynut commented 3 years ago

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:

chughts commented 3 years ago

See the answer to your question on stack overflow - https://stackoverflow.com/questions/65973220/ibm-watson-text-to-speech-api-method-failed-with-status-code-403-forbidden/65990867#65990867

the url should be https://api.us-east.text-to-speech.watson.cloud.ibm.com, if your instance is US east.

SirSpidey commented 3 years ago

I'm able to use the API via CURL.

I don't think that the endpoint is the issue if Curl succeeds. The older endpoints still work for now (although deprecated), so stream.watsonplatform.net/text-to-speech/api and api.us-south.text-to-speech.watson.cloud.ibm.com work for the Dallas location with the same API key.

mediumTaj commented 3 years ago

The endpoints you list above are for speech-to-text, text to speech and combinations of both. Can you confirm that you are using the text to speech endpoint that you are using in the curl command in your application? It might be helpful to provide both the curl command and sample authentication code you are using in your application (API keys redacted).

apaparazzi0329 commented 3 years ago

Looking into this issue again, we have located the source of the error and determined a viable solution. We expect a patch release for this in the coming days

apaparazzi0329 commented 3 years ago

This issue has been patched in version 5.2.1. Closing as resolved