python - Predicton API + GAE: Invalid Credentials -
i'm trying make gae (python) application talk prediction api, keep getting httperror: <httperror 401 when requesting ... returned "invalid credentials">
the gae code have is:
from handler_request import request_handler # extended request handler apiclient.discovery import build oauth2client.appengine import appassertioncredentials import httplib2 api_key = "<my key server apps>" http = appassertioncredentials('https://www.googleapis.com/auth/prediction').authorize(httplib2.http()) service = build('prediction', 'v1.6', http=http, developerkey=api_key) class listmodels(request_handler): def get(self): papi = service.trainedmodels() result = papi.list( project='my_project_number', maxresults=10 ).execute() self.response.headers['content-type'] = 'text/plain' self.response.out.write('result: ' + repr(result))
- all imported libraries google's python api libraries, , being imported correctly.
- i'm using, api_key, application's "key server apps" api key, understand correct 1 use case application directly trying talk prediction api
for reason, doesn't work. i've taken code directly page , adapted needs: https://developers.google.com/prediction/docs/developer-guide#predictionfromappengine
as matter of fact, if copy , paste same code, still invalid credentials
error.
any suggestions?
a few things check:
for version 1.6 of prediction api no longer need specify developerkey (so suggest not doing so), appassertioncredentials enough.
appassertioncredentials not work in local dev_appserver.py environment, make sure deploy <your app name>.appspot.com use - or @ using signedjwtassertioncredentials substitute when testing locally.
make sure service account associated app engine app added "team" in api console project has prediction api enabled.
Comments
Post a Comment