I am running this code from my laptop. I want to call a tensorlflow model which is on GCP. I try to simulate an API call from our systems to GCP.
from oauth2client.client import GoogleCredentials
import requests
import json
PROJECT = 'blabla-project'
MODEL_NAME = 'blablaModelName'
MODEL_VERSION = 'blabla_version'
token=GoogleCredentials.get_application_default().get_access_token().access_token
api = 'https://ml.googleapis.com/v1/projects/{}/models/{}/versions/{}:predict' \
.format(PROJECT, MODEL_NAME, MODEL_VERSION)
headers = {'Authorization': 'Bearer ' + token}
data = {
'instances': [
{
'X1':600,
'X2':8965,
'X3':17.93,
'X4':23,
'X5':52216.32776,
'X6':144.2442343,
'X7':0,
'X8':0,
'X9':0,
'X10':0
},
{
'X1':600,
'X2':6965,
'X3':17.93,
'X4':23,
'X5':52216.32776,
'X6':144.2442343,
'X7':0,
'X8':0,
'X9':0,
'X10':0
},
]
}
response = requests.post(api, json=data,headers=headers)
print(response)
print(response.content)
At each time I run the code I have this error.
Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.
I am using python 3.8.3 on Windows.
Can anyone tell me where the code is broken or which authentication method should I use.