Annabelle White
Annabelle White

Reputation: 11

Geocoding API's response was not valid JSON (in response to a basic search)

I am using the Geocoder gem (https://github.com/alexreisner/geocoder) version 1.8. Whenever I run Geocoder.search('Paris') in the Rails console, I get this response:

Geocoding API's response was not valid JSON
=> []

I have tried using the Geocoder gem in multiple different projects, all with the same result. It has worked in the past before. I have nothing in my Geocoder config file.

I am using Rails version 7.1.3.2 and Ruby version 3.2.2

Thank you for any help!

Edit: I tried to log the request, and this what happened:

irb(main):009> Geocoder.search('Paris')
D, [2024-05-25T13:31:53.721929 #6543] DEBUG -- : Geocoder: HTTP request being made for https://nominatim.openstreetmap.org/search?accept-language=en&addressdetails=1&format=json&q=Paris
W, [2024-05-25T13:31:54.067355 #6543]  WARN -- : Geocoding API's response was not valid JSON
D, [2024-05-25T13:31:54.067582 #6543] DEBUG -- : Raw response: <html>
<head>
<title>Access blocked</title>
</head>
<body>
<h1>Access blocked</h1>

<p>You have been blocked because you have violated the
<a href="https://operations.osmfoundation.org/policies/nominatim/">usage policy</a>
of OSM's Nominatim geocoding service. Please be aware that OSM's resources are
limited and shared between many users. The usage policy is there to ensure that
the service remains usable for everybody.</p>

<p>Please review the terms and make sure that your
software adheres to the terms. You should in particular verify that you have set a
<b>custom HTTP referrer or HTTP user agent</b> that identifies your application, and
that you are not overusing the service with massive bulk requests.</p>

<p>If you feel that this block is unjustified or remains after you have adopted
your usage, you may contact the Nominatim system administrator at
nominatim@openstreetmap.org to have this block lifted.</p>
</body>
</head>

Upvotes: 0

Views: 653

Answers (1)

Annabelle White
Annabelle White

Reputation: 11

I added

Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })

to my Geocoder config file.

Upvotes: 1

Related Questions