我正在使用 Geocoder gem (https://github.com/alexreisner/geocoder) 版本 1.8。每当我在 Rails 控制台中运行
Geocoder.search('Paris')
时,我都会收到以下响应:
Geocoding API's response was not valid JSON
=> []
我尝试在多个不同的项目中使用 Geocoder gem,所有结果都相同。它在过去曾发挥过作用。我的地理编码器配置文件中没有任何内容。
我正在使用 Rails 版本 7.1.3.2 和 Ruby 版本 3.2.2
感谢您的帮助!
编辑: 我尝试记录请求,结果是这样的:
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
[email protected] to have this block lifted.</p>
</body>
</head>
我添加了
Geocoder.configure(http_headers: { "User-Agent" => "your contact info" })
我的地理编码器配置文件。