4

I'm deploying an application which makes a request against the Google Maps Geolocation API. My requests go through fine from my workstation. But I get a 400 Bad Request error every time I run it from a server in Amazons cloud.

Below is an example curl request I'm making to test. The API in use allows for Any IP.

curl -d "{'wifiAccessPoints':[{'macAddress':'c8:d7:19:16:3b:63'},{'macAddress':'c8:d7:19:16:3b:61'}]}" -H "Content-Type: application/json" -i "https://www.googleapis.com/geolocation/v1/geolocate?key=PUTYOURKEYHERE" -v

Below is an example of the error results

* About to connect() to www.googleapis.com port 443 (#0)
*   Trying 173.194.76.95... connected
* Connected to www.googleapis.com (173.194.76.95) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using SSL_RSA_WITH_RC4_128_SHA
* Server certificate:
*   subject: CN=*.googleapis.com,O=Google Inc,L=Mountain View,ST=California,C=US
*   start date: Jan 15 14:37:40 2014 GMT
*   expire date: May 15 00:00:00 2014 GMT
*   common name: *.googleapis.com
*   issuer: CN=Google Internet Authority G2,O=Google Inc,C=US
> POST /geolocation/v1/geolocate?key=AIzaSyDzcv8DIbbeGBaONSq2kXh7g9AZbgsiUC8 HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: www.googleapis.com
> Accept: */*
> Content-Type: application/json
> Content-Length: 93
> 
< HTTP/1.1 400 Bad Request
HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=UTF-8
Content-Type: application/json; charset=UTF-8
< Date: Thu, 30 Jan 2014 10:56:18 GMT
Date: Thu, 30 Jan 2014 10:56:18 GMT
< Expires: Thu, 30 Jan 2014 10:56:18 GMT
Expires: Thu, 30 Jan 2014 10:56:18 GMT
< Cache-Control: private, max-age=0
Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
X-XSS-Protection: 1; mode=block
< Server: GSE
Server: GSE
< Alternate-Protocol: 443:quic
Alternate-Protocol: 443:quic
< Transfer-Encoding: chunked
Transfer-Encoding: chunked

< 
{
 "error": {
  "errors": [
   {
    "domain": "geolocation",
    "reason": "invalidRequest",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}
* Connection #0 to host www.googleapis.com left intact
* Closing connection #0
  • 1
    Possible duplicate of [Google Geocoding service returns Error 400 Bad Request](http://stackoverflow.com/questions/5395860/google-geocoding-service-returns-error-400-bad-request). But you will probably need to use the client geocoder. [Keys aren't allowed in the Geocoding API](http://stackoverflow.com/questions/19919318/google-maps-geocode-i-get-a-new-api-key-and-it-claims-its-invalid/19919791#19919791). Shared servers share quota on geocoder requests from the server (unless you have a Maps for Business client id). – geocodezip Jan 28 '14 at 21:15
  • I am using the Geolocation API, not the Geocoding API. The above request works from everywhere I test it, except from Amazon. – user3246295 Jan 28 '14 at 21:50
  • Can you include the curl `-v` switch and share the curl output from your EC2 instance? – Steve Jansen Jan 29 '14 at 01:37
  • Added the verbose results as requested – user3246295 Jan 30 '14 at 10:58
  • @steve When I run curl withe the verbose switch, I do see one important difference, `* upload completely sent off: 93 out of 93 bytes` – user3246295 Jan 30 '14 at 11:05
  • @user3246295 I'm having the [same issue](http://stackoverflow.com/questions/30007908/google-geolocation-using-cell-tower-info-curl-400-bad-request-php) . Did you solve it ? Thanks – chaithu May 03 '15 at 06:47

1 Answers1

2

I had the exact same problem, for some reason the same curl command would work on ubuntu but not on amazon ami (centos). The solution was to add considerIp: false to the request body, like this:

{
    "considerIp": false,
    "wifiAccessPoints": [
        ...
    ]
}
brunodea
  • 220
  • 1
  • 10