androidpythongoogle-app-enginegoogle-cloud-endpointsendpoints

Invalid double value after cast from float with GAE endpoints


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.


Solution

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