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.46k stars 827 forks source link

Visual Recognition instance creation fails when using with IBM cloud function #570

Closed sanjeevghimire closed 6 years ago

sanjeevghimire commented 6 years ago

Expected behavior

should create the instance without failing

Actual behavior

"2018-09-25T01:36:26.085974249Z stderr: File \"/usr/local/lib/python3.6/site-packages/watson_developer_cloud/visual_recognition_v3.py\", line 169, in classify"
--
12 | "2018-09-25T01:36:26.085978723Z stderr: accept_json=True)"
13 | "2018-09-25T01:36:26.085982683Z stderr: File \"/usr/local/lib/python3.6/site-packages/watson_developer_cloud/watson_service.py\", line 423, in request"
14 | "2018-09-25T01:36:26.085987088Z stderr: access_token = self.token_manager.get_token()"
15 | "2018-09-25T01:36:26.085991142Z stderr: File \"/usr/local/lib/python3.6/site-packages/watson_developer_cloud/iam_token_manager.py\", line 47, in get_token"
16 | "2018-09-25T01:36:26.085995389Z stderr: token_info = self._request_token()"
17 | "2018-09-25T01:36:26.085999277Z stderr: File \"/usr/local/lib/python3.6/site-packages/watson_developer_cloud/iam_token_manager.py\", line 78, in _request_token"
18 | "2018-09-25T01:36:26.086003549Z stderr: data=data)"
19 | "2018-09-25T01:36:26.0860074Z   stderr: File \"/usr/local/lib/python3.6/site-packages/watson_developer_cloud/iam_token_manager.py\", line 34, in request"
20 | "2018-09-25T01:36:26.086011707Z stderr: raise WatsonApiException(response.status_code, message=error_message, httpResponse=response)"
21 | "2018-09-25T01:36:26.086015998Z stderr: watson_developer_cloud.watson_service.WatsonApiException: Error: Not Found, Code: 404 , X-dp-watson-tran-id: gateway01-994079057 , X-global-transaction-id: 7ecac92c5ba9911a3b407151"
start | 1537839384689

Steps to reproduce the problem

create the instance part of IBM Cloud function and upload it. I am using the SDK part of the IBM cloud function runtime using: I created the function using:

ibmcloud wsk action create WatsonModerator functions/bot_moderator_function.py --param-file params.json --kind python-jessie:3

Code snippet (Note: Do not paste your credentials)

visual_recognition = VisualRecognitionV3( '2016-05-20', iam_url='https://gateway.watsonplatform.net/visual-recognition/api', iam_api_key='' )

python sdk version

1.7.0 - which is the one in IBM Cloud Function runtime

python version

3.6

sanjeevghimire commented 6 years ago

if i don't pass the url above i get this error:


"2018-09-25T16:37:26.250051212Z stdout: Downloading image..."
--
3 | "2018-09-25T16:37:26.769502112Z stdout: Saving image locally ..."
4 | "2018-09-25T16:37:26.769821947Z stdout: Checking image for explicit content...https://files.slack.com/files-pri/T4CHDRF36-FD0JHM9D1/explicit.jpg"
6 | "2018-09-25T16:37:27.088759172Z stderr: Traceback (most recent call last):"
7 | "2018-09-25T16:37:27.088793662Z stderr: File \"pythonrunner.py\", line 88, in run"
8 | "2018-09-25T16:37:27.088799045Z stderr: exec('fun = %s(param)' % self.mainFn, self.global_context)"
9 | "2018-09-25T16:37:27.088803428Z stderr: File \"<string>\", line 1, in <module>"
10 | "2018-09-25T16:37:27.088808468Z stderr: File \"__main__.py\", line 49, in main"
11 | "2018-09-25T16:37:27.088812967Z stderr: File \"/usr/local/lib/python3.6/site-packages/watson_developer_cloud/visual_recognition_v3.py\", line 169, in classify"
12 | "2018-09-25T16:37:27.088817319Z stderr: accept_json=True)"
13 | "2018-09-25T16:37:27.088821309Z stderr: File \"/usr/local/lib/python3.6/site-packages/watson_developer_cloud/watson_service.py\", line 468, in request"
14 | "2018-09-25T16:37:27.088825473Z stderr: info=error_info, httpResponse=response)"
15 | "2018-09-25T16:37:27.088829646Z stderr: watson_developer_cloud.watson_service.WatsonApiException: Error: Unknown error, Code: 400 , X-dp-watson-tran-id: gateway02-524559655 , X-global-transaction-id: ffea405d5baa64461f442527"
ehdsouza commented 6 years ago

The API url is url='https://gateway.watsonplatform.net/visual-recognition/api'

sanjeevghimire commented 6 years ago

@ehdsouza the url is optional right? I get 400 errorif I don’t pass url

ehdsouza commented 6 years ago

Are you using a cloud foundry or resource controller instance?

sanjeevghimire commented 6 years ago

@ehdsouza I am using IBM Cloud Functions and using the watson developer cloud SDK provided.

ehdsouza commented 6 years ago

The url depends on which region your visual recognition instance is in. Do check in the service dashboard: https://console.bluemix.net/dashboard/apps/ for the url of your service instance