1

I'm trying to connect to a Language Translator instance as per the docs:

!pip install --upgrade "watson-developer-cloud>=1.4.0"

import json
from watson_developer_cloud import LanguageTranslatorV2

translator = LanguageTranslatorV2(
    iam_api_key='***my_api_key***',
    url='https://gateway.watsonplatform.net/language-translator/api'
)

models = translator.list_models()
print(json.dumps(models, indent=2))

However, this results in:

WatsonApiException: Error: Unauthorized: Access is denied due to invalid credentials , Code: 401 , Information: {'description': 'No credentials supplied.'} , X-dp-watson-tran-id: xxxxxx , X-global-transaction-id: xxxxx

I found the API Key in the service credentials. I tried both apikey and iam_apikey_name but both result in the same error:

{
 “apikey”: “***my_api_key***”,
 “iam_apikey_description”: “Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:language-translator:us-south:xxxxxx::“,
 “iam_apikey_name”: “auto-generated-apikey-xxxxxx",
 “iam_role_crn”: “crn:v1:bluemix:public:iam::::serviceRole:Manager”,
 “iam_serviceid_crn”: “crn:v1:bluemix:public:iam-identity::xxxxxx::serviceid:ServiceId-xxxxxx",
 “url”: “https://gateway.watsonplatform.net/language-translator/api”
}

I also tried creating a Platform API Key for IBM Cloud. Same error.

I also tried creating an access token:

%%bash
curl -k -X POST \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --header "Accept: application/json" \
  --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \
  --data-urlencode "apikey=**myapikey**" \
  "https://iam.bluemix.net/identity/token"

Then using the access token returned by curl:

translator = LanguageTranslatorV2(iam_access_token='**generated_access_token**')

Same error :(

I think this issue is similar to this question posted for VisualRecognition, but in this case for LanguageTranslator.

Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • Which instance? The announcement says that not all have been migrated https://console.bluemix.net/docs/services/language-translator/release-notes.html#release-notes – data_henrik Jun 20 '18 at 10:02
  • Just finding out. I'm posting on behalf of another user who is hitting issues going through the tutorial https://www.ibm.com/cloud/garage/tutorials/ibm-watson-studio-machine-learning/ibm-watson-studio-ml-dl-made-easy – Chris Snow Jun 20 '18 at 11:19
  • @data_henrik I just tried with a new service created in US South. I tried different ways to setup the library (question has been updated). All produced the same error – Chris Snow Jun 20 '18 at 11:28

1 Answers1

2

Language Translator now has a V3 version of the service. Perhaps you created a V3 service instance? If so, you need to use the LanguageTranslatorV3 module in the Watson Python SDK.

Mike Kistler
  • 437
  • 2
  • 10