Nominatim-responses from OpenStreetMap no longer readable

I am retrieving reverse lookups of GPS-Data (issuing “latitude“ and “longitude“) to get the address of the supplied location from nominatim/OpenStreetMap.

For example: I have the GPS-coordinates lat=50.59865 & lon=8.41693.
by issuing:

https://nominatim.openstreetmap.org/reverse?lat=50.59865&lon=8.41693&zoom=20&format=json&accept-language=de_DE&addressdetails=1

I expect to get the following json as response:

{"place_id":127743226,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright","osm_type":"way","osm_id":921342942,"lat":"50.5986804","lon":"8.4167133","class":"building","type":"yes","place_rank":30,"importance":5.143434805824395e-05,"addresstype":"building","name":"","display_name":"41, Bachstraße, Werdorf, Aßlar, Lahn-Dill-Kreis, Hessen, 35614, Deutschland","address":{"house_number":"41","road":"Bachstraße","village":"Werdorf","municipality":"Aßlar","county":"Lahn-Dill-Kreis","state":"Hessen","ISO3166-2-lvl4":"DE-HE","postcode":"35614","country":"Deutschland","country_code":"de"},"boundingbox":["50.5986344","50.5987271","8.4166294","8.4167991"]}

This works fine with a browser (Chrome / Firefox) and used to work fine with Java/JSoup also until last year.

Response response=Jsoup
    .connect(url)
    .timeout(20000) 
        .header("Content-Type","application/json; charset=utf-8")
    .header("Accept-Encoding","gzip,deflate,br")
    .method(Method.GET)
    .maxBodySize(0)
    .ignoreContentType(true)
    .execute();

But now I get a “Status=403 / Forbidden”.

I compared this request header to the browsers request header and added the userAgent(DEFAULT_UA) to the request

This is the new request now:

Response response=Jsoup
    .connect(url)
    .timeout(20000) 
        .header("Content-Type","application/json; charset=utf-8")
    .header("Accept-Encoding","gzip,deflate,br")
    .userAgent(DEFAULT_UA)
    .method(Method.GET)
    .maxBodySize(0)
    .ignoreContentType(true)
    .execute();

The response looks like this. I don’t know the encoding.

fGHfrQ6t

You have explicitly told the server that you will accept responses in gzip, deflate, or Brotli (“br”) encoding. The server will choose any of these and tell you in the returned Content-type header which one it chose - in this case

content-encoding: br

which means your content got Brotli-encoded as per your request. If you cannot handle this, then don’t ask for it. Drop the “Accept-Encoding” header and you get plain JSON.

PS (edit): It is recommended that you set a user agent header that will allow the server operators to identify your application. Default user agents are not permitted per Nominatim Usage Policy (aka Geocoding Policy) - you could see a 403 response anytime if you continue to use “DEFAULT_UA”.

9 Likes

In general, reading Nominatim Usage Policy (aka Geocoding Policy) is worth doing if you use these servers.

3 Likes