Hit Watson's REST API from Python on IBM Bluemix

In the middle of writing. unfinished

Registration

Register with IBM BlueMix

Creating a space dev http://www.creationline.com/lab/8055 I'm doing it with CLI here, but I think I could do it normally with GUI.

Go to dashboard Select a catalog from the menu Select Python If the name specified at this time overlaps with an existing one, it cannot be added. Select the one you added on the dashboard Add the Watson Question & Answer service by adding the service. At the time of addition, the URL, ID, and password for using the API have been issued.

Q & A is one of the services added to the dashboard. If you display the credentials here, you can check the url, id, password. Also, there is a link to the document to the right of the credential display, so take a look. Looking at the api reference in the documentation, they are all REST APIs. In this case, I think that the REST API should be recognized as returning a JSON-formatted response when accessed by url. To skip the ping to the Q & A API, it says v1 / ping. Try accessing it with a browser and check it. I'm returning 200 as an http request response, but I see an empty JSON on the browser {} Try accessing it from the terminal. ..

curl -X GET -H "Accept: application/json" -u d1447bde-bb6f-4db9-b073-eb8faadcf96d:6aX7RxuNFtJp https://gateway.watsonplatform.net/question-and-answer-beta/api/v1/ping {} https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Virtualization/3.0/html/REST_API_Guide/appe-REST_API_Guide-cURL_Integration.html

curl -u d1447bde-bb6f-4db9-b073-eb8faadcf96d:6aX7RxuNFtJp -LI https://gateway.watsonplatform.net/question-and-answer-beta/api/v1/ping -o /dev/null -w '%{http_code}\n' -s 200

http://sugamasao.hatenablog.com/entry/20120326/1332754813

Web application development using Django http://www.ibm.com/developerworks/jp/cloud/library/cl-worldbank-charting-app/ Let's try only steps 1 and 2 here. It is displayed as It works.

Install cf & push

Next, let's deploy this. Select an app from the dashboard Choose to start coding If you select the CF command line interface, the explanation will appear, so follow it.

http://www.ibm.com/developerworks/jp/cloud/library/cl-worldbank-charting-app/ Follow step 4 of step 4 to upload your Django project on BlueMix. Just write the environment information in requirement.txt and the environment will be built on the server. Feel the future of today.

Django http://www.ibm.com/developerworks/jp/cloud/library/cl-worldbank-charting-app/

git clone https://hub.jazz.net/git/mamtasharma/trendsapp001 And download the source

manifest.yml Change name to a unique name Delete the build line

For the time being, I want to move Django somehow, so the details are insects cf push --no-start cf create-service mongodb 100 mongodb001 cf bind-service trendsapp001 mongodb001 cf start trendsapp001

Access url / trends It worked.

Add Q & A

Go to the dashboard and go to the app page With the addition of services

https://developer.ibm.com/answers/questions/181645/question-validation-failed-error-when-making-post.html Can not! Python Script

request.py


import requests
import json
 
qt = "How deep is grand canyon?"
url = "https://gateway.watsonplatform.net/question-and-answer-beta/api/v1/question/travel"
r = requests.post(url,
                  data=json.dumps({"question": {"questionText": qt}}),
                  headers={"Content-Type": "application/json", "X-SyncTimeout": 30},
                  auth=("0b46d272-3d88-47c7-afa5-9127919e83a6", "yhxjoHEq3dmP"))
print r.text

Since Django 1.7 has been using new features, Not very helpful in the past. http://a-records.info/2014/09/29/18/

Recommended Posts

Hit Watson's REST API from Python on IBM Bluemix
Hit Mastodon's API in Python
Use e-Stat API from Python
Hit REST in Python to get data from New Relic
Hit treasure data from Python Pandas
[Python] Hit the Google Translation API
Notes on using MeCab from Python
Hit the Etherpad-lite API with Python
Use kabu StationĀ® API from Python
Use the Flickr API from Python
Get upcoming weather from python weather api
Notes on accessing dashDB from python
Quickly implement REST API in Python
Run Ansible from Python using API
Use Google Analytics API from Python
Handle SOAP API from Python (Zeep)
Call C / C ++ from Python on Mac
Update Python on Mac from 2 to 3
Points to consider when hitting SoftLayer API from an app on Bluemix
Collecting information from Twitter with Python (Twitter API)
[Python] Web application from 0! Hands-on (3) -API implementation-
Python: Reading JSON data from web API
[Python] REST API essential, convenient library summary
Connecting from python to MySQL on CentOS 6.4
Use Google Cloud Vision API from Python
I tried using UnityCloudBuild API from Python
API explanation to touch mastodon from python
Connect to coincheck's Websocket API from Python
Get users belonging to your organization from Garoon REST API with Python + Requests
[IBM Cloud] I tried to access the Db2 on Cloud table from Cloud Funtions (python)
Put the exchange rate obtained from Oanda REST API in Python into MongoDB
PHP and Python integration from scratch on Laravel
[Node-RED] Execute Python on Anaconda virtual environment from Node-RED [Anaconda] [Python]
(Note) Basic statistics on Python & Pandas on IBM DSX
[WP REST API v2] Upload images in Python
Create a Python execution environment on IBM i
Hit the Firebase Dynamic Links API in Python
Try accessing the YQL API directly from Python 3
Notes on oct2py calling Octave scripts from Python