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))
- All imported libraries are Google's python API libraries, and are being imported correctly.
- I'm using, as api_key, my application's "Key for server apps" API Key, as I understand this is the correct one for my use case as my application is directly trying to talk to the Prediction API
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?