0

I get errors when posting prediction requests, but when posting the same requests from the online interface (from Google's API reference page) works well. I have also posted a new issue on the Git repository, but it seems that no-one even looks at these issues. How lame of Google !!

Well I am posting predict request, which look like this:

var parameters = {
auth: jwtClient,
project: googleProjectID,
id: 'interest_classifier',
input: {
csvInstance: ["country united states", "/location/location"]
}
};
return prediction.trainedmodels.predict(parameters, function(err, response) {
if (err) {
logger.info(null, "prediction err ", err);
}
logger.info(null, "response from predict ", response);
return callback(null, response);
});

And I get this:

err { [Error: Input data invalid.]
code: 400,
errors:
[ { domain: 'global',
reason: 'invalidValue',
message: 'Input data invalid.' } ] }

To clarify: my trained model contains a value and two textual features. Again, when running this from the online tool (client side) it works well, only when I run it from my node.js server, does it fail.

What's up with that? Anyone knows? Could this be some encoding issue? request headers?

EDIT:

this is how i authenticate :

var   jwtClient = new google.auth.JWT('*****@developer.gserviceaccount.com', 'keys/key.pem', null, ['https://www.googleapis.com/auth/prediction']);

  jwtClient.authorize(function(err, tokens) {
    logger.info(null, "authorizing");
    if (err) {
      logger.info(null, "error ", err);
    } else {
      return logger.info(null, "authenticated ", tokens);
    }
  });
Ilan lewin
  • 1,599
  • 1
  • 14
  • 24

1 Answers1

0

OK,

So I've dug into Google's code and found out an important detail that is not properly documented.

I think this might be relevant to other people using this library, not only the ones who use google predict.

So most requests need to include a project id in the parameters, but in some cases you also need to include post data (like in my case). I was trying to include this post data directly in the parameters like so :

var parameters = {
auth: jwtClient,
project: googleProjectID,
id: 'interest_classifier',
input: {
csvInstance: ["country united states", "/location/location"]
}
};

Now I found (this is not documented !!) that the whole part which belongs to the post data should be included within a "resource" field, like this:

var parameters = {
auth: jwtClient,
project: googleProjectID,
id: 'interest_classifier',
resource:{
input: {
csvInstance: ["country united states", "/location/location"]
}
}
};

I believe this will be relevant to any request which includes post data. Cheers, Ilan

Ilan lewin
  • 1,599
  • 1
  • 14
  • 24