Python Forum
Issue with geolocator = Nominatim - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Issue with geolocator = Nominatim (/thread-31330.html)



Issue with geolocator = Nominatim - bborusz2 - Dec-04-2020

Hey guys,

Hoping someone can explain the issue I'm having with Geolocator...it was working fine yesterday, but now when I run the cell it is coming back with Gateway 502 error. Attached below is the code and error message.

address = 'Chicago, IL, USA'

geolocator = Nominatim(user_agent="class-app")
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
print('The geographical coordinate of Chicago are {}, {}.'.format(latitude, longitude))
Error:
AdapterHTTPError Traceback (most recent call last) /opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, callback, timeout, is_json, headers) 359 if is_json: --> 360 result = self.adapter.get_json(url, timeout=timeout, headers=req_headers) 361 else: /opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/geopy/adapters.py in get_json(self, url, timeout, headers) 372 def get_json(self, url, *, timeout, headers): --> 373 resp = self._request(url, timeout=timeout, headers=headers) 374 try: /opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/geopy/adapters.py in _request(self, url, timeout, headers) 403 status_code=resp.status_code, --> 404 text=resp.text, 405 ) AdapterHTTPError: Non-successful status code 502 The above exception was the direct cause of the following exception: GeocoderServiceError Traceback (most recent call last) <ipython-input-52-b44a620f75c6> in <module> 2 3 geolocator = Nominatim(user_agent="class-app") ----> 4 location = geolocator.geocode(address) 5 latitude = location.latitude 6 longitude = location.longitude /opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/geopy/geocoders/nominatim.py in geocode(self, query, exactly_one, timeout, limit, addressdetails, language, geometry, extratags, country_codes, viewbox, bounded, featuretype, namedetails) 292 logger.debug("%s.geocode: %s", self.__class__.__name__, url) 293 callback = partial(self._parse_json, exactly_one=exactly_one) --> 294 return self._call_geocoder(url, callback, timeout=timeout) 295 296 def reverse( /opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/geopy/geocoders/base.py in _call_geocoder(self, url, callback, timeout, is_json, headers) 376 return callback(result) 377 except Exception as error: --> 378 self._adapter_error_handler(error) 379 raise 380 /opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/geopy/geocoders/base.py in _adapter_error_handler(self, error) 390 self._geocoder_exception_handler(error) 391 exc_cls = ERROR_CODE_MAP.get(error.status_code, GeocoderServiceError) --> 392 raise exc_cls(str(error)) from error 393 else: 394 self._geocoder_exception_handler(error) GeocoderServiceError: Non-successful status code 502
Please advise what I am doing wrong.

Thank you.


RE: Issue with geolocator = Nominatim - buran - Dec-04-2020

probably some temporary problem with Nominatim
right now, if you try the examples here:
https://nominatim.org/release-docs/develop/api/Search/

the xml link return 502 Bad Gateway
https://nominatim.openstreetmap.org/search?q=135+pilkington+avenue,+birmingham&format=xml&polygon_geojson=1&addressdetails=1


while the JSON link example works
https://nominatim.openstreetmap.org/search/Unter%20den%20Linden%201%20Berlin?format=json&addressdetails=1&limit=1&polygon_svg=1


RE: Issue with geolocator = Nominatim - buran - Dec-04-2020

OK, now it works, incl. your code


RE: Issue with geolocator = Nominatim - bborusz2 - Dec-04-2020

(Dec-04-2020, 04:57 PM)buran Wrote: OK, now it works, incl. your code

Thanks for the help! Just learning all of these things.