Reputation: 2738
I'm trying to make my GAE (python) Application talk to the Prediction API, but I keep getting HttpError: <HttpError 401 when requesting ... returned "Invalid Credentials">
The GAE code I have is:
from handler_request import Request_Handler # My extended Request Handler
from apiclient.discovery import build
from oauth2client.appengine import AppAssertionCredentials
import httplib2
api_key = "<my key for 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))
For some reason, this doesn't work. I've taken this code directly from this page and adapted it to my needs: https://developers.google.com/prediction/docs/developer-guide#predictionfromappengine
As a matter of fact, if I copy and paste that same code, I still get an Invalid Credentials
error.
Any suggestions?
Upvotes: 0
Views: 529
Reputation: 2457
A few things to check:
For version 1.6 of Prediction API you no longer need to specify the developerKey (so I would suggest not doing so), AppAssertionCredentials is enough.
AppAssertionCredentials will not work in the local dev_appserver.py environment, make sure you deploy to <your app name>.appspot.com to use - or look at using a SignedJwtAssertionCredentials as a substitute when testing locally.
Make sure that the service account associated with the App Engine app is added to the "Team" in the API Console for the project that has Prediction API enabled.
Upvotes: 2