Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

IndexError on failed reverse geocodes #8

Closed
llimllib opened this issue Jul 26, 2020 · 3 comments
Closed

IndexError on failed reverse geocodes #8

llimllib opened this issue Jul 26, 2020 · 3 comments

Comments

@llimllib
Copy link

llimllib commented Jul 26, 2020

I live in Portland, Maine so if I search for Portland it almost always brings up Oregon. Therefore the first thing I did when downloading this was:

$ felicette -l "Portland, ME"
Traceback (most recent call last):
  File "/Users/llimllib/.pyenv/versions/3.8.5/bin/felicette", line 8, in <module>
    sys.exit(main())
  File "/Users/llimllib/.pyenv/versions/3.8.5/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/llimllib/.pyenv/versions/3.8.5/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/llimllib/.pyenv/versions/3.8.5/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/llimllib/.pyenv/versions/3.8.5/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/llimllib/.pyenv/versions/3.8.5/lib/python3.8/site-packages/felicette/cli.py", line 50, in main
    coordinates = geocoder_util(location_name)
  File "/Users/llimllib/.pyenv/versions/3.8.5/lib/python3.8/site-packages/felicette/utils/geo_utils.py", line 19, in geocoder_util
    return (float(r_json[0]["lon"]), float(r_json[0]["lat"]))
IndexError: list index out of range

I debugged into it a bit and nominatim returns empty results for Portland Maine and Portland, ME:

$ curl 'https://nominatim.openstreetmap.org/search?city=Portland%20Maine&format=json'
[]
$ curl 'https://nominatim.openstreetmap.org/search?city=Portland,%20ME&format=json'
[]

It would be best if the reverse geocode worked, but also totally OK for felicette to print out an understandable error if the reverse geocode failed.

@llimllib
Copy link
Author

fwiw, this very similar query works:

 curl 'https://nominatim.openstreetmap.org/search.php?q=Portland%2C+maine&format=json'
[{"place_id":235457607,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":132500,"boundingbox":["43.606363","43.727658","-70.346095","-70.076935"],"lat":"43.6610277","lon":"-70.2548596","display_name":"Portland, Cumberland County, Maine, United States of America","class":"boundary","type":"administrative","importance":0.7629710139286798,"icon":"https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png"},{"place_id":77924609,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"node","osm_id":7030623591,"boundingbox":["43.6489391","43.6589391","-70.2962915","-70.2862915"],"lat":"43.6539391","lon":"-70.2912915","display_name":"Portland, Thompsons Point Connector Road, Libbytown, Portland, Cumberland County, Maine, 04102, United States of America","class":"railway","type":"station","importance":0.4432286868188654,"icon":"https://nominatim.openstreetmap.org/images/mapicons/transport_train_station2.p.20.png"},{"place_id":27931287,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"node","osm_id":2702922008,"boundingbox":["43.6529626","43.6530626","-70.2908435","-70.2907435"],"lat":"43.6530126","lon":"-70.2907935","display_name":"Portland, Thompsons Point, Libbytown, Portland, Cumberland County, Maine, 04102, United States of America","class":"railway","type":"stop","importance":0.21100000000000002}]

I didn't look at their docs at all, so I don't know if you're not supposed to hit that endpoint or something; I just copied from the network inspector and guessed.

@plant99
Copy link
Owner

plant99 commented Jul 26, 2020

Understood, this is unwanted but expected behavior since I'm not checking for a valid list before returning results here. https://github.com/plant99/felicette/blob/master/felicette/utils/geo_utils.py#L19
Thanks for bringing this up!

@plant99
Copy link
Owner

plant99 commented Jul 26, 2020

Fixed with this commit, df507be
Will notify here, when it's released next.

@plant99 plant99 closed this as completed Jul 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants