0

I am using the endpoints API from google cloud and sending double, which are cast from float in Android. Most of the time this works well, but I have noticed that with a small number of devices I get a following error:

400 Bad Request

{
    "code": 400,
    "errors": [{
        "domain": "global",
        "location": "longitude",
        "locationType": "parameter",
        "message": "Invalid double value: '116.31765747070313'.",
        "reason": "invalidParameter"
    }],
    "message": "Invalid double value: '116.31765747070313'."
}

Here is the code on android side:

void callEndpoints(final int level, final float latitude, final float longitude) {
    try {
        API.GetPlacesFromLocationV2 remoteData = cbAPI.getPlacesFromLocationV2();

        remoteData.setLatitude((double)latitude);
        remoteData.setLongitude((double)longitude);
        remoteData.setLevel((long) level);

        Result res = remoteData.execute();

        //Do stuff with res
    } catch (IOException e) {
        //print error
    }
}

Here is the python server side code.

PLACES_LOCATION_SEARCH_V2_CONTAINER = endpoints.ResourceContainer(
   message_types.VoidMessage,
   level=messages.IntegerField(1),
   longitude=messages.FloatField(2),
   latitude=messages.FloatField(3)
)

def getCellIdx(level, lon, lat):
   scale = pow(2, level)
   cellWidth = FULL_WIDTH / scale
   cellHeight = FULL_HEIGHT / scale

   wIdx = int((lon + 180.0) / cellWidth)
   hIdx = int((lat + 90.0) / cellHeight)

   return level * 100000000 + hIdx * 10000 + wIdx

@endpoints.method(PLACES_LOCATION_SEARCH_V2_CONTAINER, 
   DataCollection, 
   path="getPlacesFromLocation_v2", http_method='GET', 
   name="getPlacesFromLocation_v2")
def getPlacesFromLocation_v2(self, request):
  cellIdx = placesGridSearch.getCellIdx(request.level,request.longitude,request.latitude)
  #Do stuff with cellIdx, includes datastore access and memcache usage
  return DataCollection(cellIdx)

Thanks for your help.

Edit: Some additional information, I get the same error if I run it through the API explorer with the same value for longitude on cloud, but not if I run it on my local development server. It also looks like the endpoints function is never called (there is no log) but there is a /_ah/spi/BackendService.logMessages log describing the exact same error.

dk_dev
  • 315
  • 4
  • 12

1 Answers1

1

Upgrade to Endpoints Frameworks v2. It will not have this issue.

saiyr
  • 2,575
  • 1
  • 11
  • 13
  • Thank you for your suggestion. This has been on my todo list for a while. I just upgraded it. I followed the instructions but now I get a "No handlers matched this URL." on the server side. The requests from the users apps are still going to /_ah/spi/... which I changed in the app.yaml to /_ah/api/.* according to the instructions. Do I have to release a new version of the app? And if yes, how do I handle the server side at the same time? Thanks. – dk_dev Oct 18 '17 at 11:46
  • Btw. I only had 10% of traffic going to the new version of my live server. Could this be the problem? On my test server (also on the cloud) it seems to be working fine. There I had 100% traffic going to it. – dk_dev Oct 18 '17 at 11:49
  • Yeah, don't use traffic splitting for this. After you migrate, traffic splitting should work. You shouldn't need a new version of your client, only your server. – saiyr Oct 18 '17 at 16:46
  • Thanks! It's on endpoints v2 now. I'll see if the errors disappear now. – dk_dev Oct 19 '17 at 02:32
  • Looks like this fixed the error. But I now have for one of the endpoints this error: "No endpoint found for path:". It only happens in less then 3% of the calls. Any ideas? Thanks for your help. – dk_dev Oct 19 '17 at 23:45
  • Never mind. Looks like the client side is calling this endpoints from time to time without parameters. – dk_dev Oct 20 '17 at 00:00