How to access Google Prediction API with Python? -
i have practice project given me advisor asks me write python script access model trained prediction api using api explorer. have 2 questions regarding this,
the guidelines specify should not check in credentials in python script , not sure means, leads question...
when follow documentation call "predict" method of "trainedmodels" (to predict language of text using trained model)
from apiclient import discovery service = discovery.build('prediction','v1.6') x = service.trainedmodels().predict(project='my first project', id='my_project_id', body={"input":{"csvinstance":['bonjour!']}})
this return value
<googleapiclient.http.httprequest object @ 0x1031996d0>
because not aware of meant "not checking in credentials", unclear how proceed in resolving problem.
thank in advance.
there @ least ways achieve that:
- using gcloud tool store credentials locally (https://cloud.google.com/sdk/gcloud/#gcloud.auth). accessible within python app below.
- creating configuration file , retrieve credentials there
here's snippet showing how access credentials within python:
http = appassertioncredentials('https://www.googleapis.com/auth/prediction https://www.googleapis.com/auth/devstorage.read_only').authorize(httplib2.http()) service = build('prediction', 'v1.6', http=http)
Comments
Post a Comment