我正在使用来自google cloud的端点API并发送double,这是从Android中的float转换而来的。大多数时候这种方法效果很好,但我注意到使用少量设备时会出现以下错误:
400错误请求
{
"code": 400,
"errors": [{
"domain": "global",
"location": "longitude",
"locationType": "parameter",
"message": "Invalid double value: '116.31765747070313'.",
"reason": "invalidParameter"
}],
"message": "Invalid double value: '116.31765747070313'."
}
以下是android端的代码:
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
}
}
这是python服务器端代码。
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)
感谢您的帮助。
编辑: 一些额外的信息,如果我通过API浏览器运行它与云上的经度相同的值,我会得到相同的错误,但如果我在我的本地开发服务器上运行它,则不会。 它看起来似乎永远不会调用端点函数(没有日志),但是有一个/_ah/spi/BackendService.logMessages日志描述完全相同的错误。