-1

I am using geopy package to get the location geocode but always run to the HTTP Error 400: Bad Request.

Below is my code, which follows the official document https://geopy.readthedocs.io/en/stable/:

from geopy.geocoders import ArcGIS
geolocator = ArcGIS(scheme="http")
loc_home = geolocator.geocode("175 5th Avenue NYC")

Below is the error:

geopy.exc.GeocoderQueryError: HTTP Error 400: Bad Request

Please help and thanks in advance!

MAMS
  • 419
  • 1
  • 6
  • 17

1 Answers1

2

You'll need to use https scheme, I guess the http is blocked by ArcGIS.

from geopy.geocoders import ArcGIS
geolocator = ArcGIS(scheme="https")

geolocator.geocode("175 5th Avenue NYC")

#Location(175 5th Ave, New York, 10010, (40.741110006692395, -73.98968797828522, 0.0))
RobinFrcd
  • 4,439
  • 4
  • 25
  • 49
  • Thanks for the comment. Yes I tried using https and got the SSL certificate error: geopy.exc.GeocoderServiceError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076). I think this is related to our internal setup, but the http error of bad request is wired. I can connect ArcGIS using http as I can print out the geolocator object after, but just getting this Error 400, which looks like related to invalid parameter value passed to the geocode function. – MAMS Oct 04 '20 at 21:09
  • If the `https` works but not `http`, either the geopy wrapper is bugged or ArcGIS blocks unsecured requests. have you tried https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error ? – RobinFrcd Oct 04 '20 at 21:14
  • They also provide their own wrapper, have you tried it ? https://developers.arcgis.com/python/guide/install-and-set-up/ – RobinFrcd Oct 04 '20 at 21:23
  • 1
    Thanks for the suggestions. After additional debugging, we identified this is because the connection to geopy API from our server is blocked. – MAMS Oct 08 '20 at 15:52
  • geopy doesn't have any API. See https://geopy.readthedocs.io/en/stable/#geopy-is-not-a-service – KostyaEsmukov Oct 10 '20 at 07:07