Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opencage lookup broken #292

Closed
nyejon opened this issue Sep 13, 2017 · 8 comments
Closed

Opencage lookup broken #292

nyejon opened this issue Sep 13, 2017 · 8 comments
Assignees

Comments

@nyejon
Copy link
Contributor

nyejon commented Sep 13, 2017

Hi,

The Opencage lookup seems to be broken again. I get the following error:

 File "..\lib\site-packages\geocoder\base.py", line 120, in _parse_json_with_fieldnames
    value = getattr(self, key)
  File "..\lib\site-packages\geocoder\opencage.py", line 359, in bbox
    south = self.raw['bounds']['southwest'].get('lat')

I can solve it by putting a try, except around the bit:

            try:
                value = getattr(self, key)
                if value:
                    self.json[key] = value
            except Exception as e:
                print(e)

but I'm not sure that that is the best solution... :)

I'm not sure how the new multiple search results have changed things and if it will be a general error, or only an error with opencage.

@nyejon
Copy link
Contributor Author

nyejon commented Sep 13, 2017

Also another question, before if I did the following:

opencage = geocoder.opencage(address, key=settings.OPENCAGE_API_KEY, countrycode=country, no_annotations=1)
print(opencage.latlng, opencage.address)

It would just print None if there wasn't a result. Now it gives an error and I have to first do:

opencage = geocoder.opencage(address, key=settings.OPENCAGE_API_KEY, countrycode=country, no_annotations=1)
if opencage.status == 'OK':
   print(opencage.latlng, opencage.address)
   return (opencage.lat, opencage.lng)

else:
   return (None, None)

is this the new intended behavior?

@ebreton
Copy link
Collaborator

ebreton commented Sep 13, 2017

Hi @nyejon ,

The Opencage lookup seems to be broken again. I get the following error

Could you please provide the initial call you made (to allow me to reproduce) and the full stack (I can't see enough in your first message to diagnostic)

>>> from geocoder import opencage
>>> g = opencage('1552 Payette dr., Ottawa')
>>> g.bbox
{'northeast': [-75.4972762, 45.4701908], 'southwest': [-75.4974667, 45.4700396]}

is this the new intended behavior?

nope. We wanted to be backward compatible. And this problem is fore sure a general one from base.py line 597.

This one is straightforward to fix (return None instead of raising an exception).
Thanks for pointing it out !

I am therefore waiting on your feedback for the first one before making a PR to correct all of it.

Cheers,
Manu

@nyejon
Copy link
Contributor Author

nyejon commented Sep 14, 2017

Hi,

I think it is just that there is no 'bounds' in many of the opencage json responses.

I am not even trying to use the bbox attribute, I think it is something to do with the:

        for key in dir(self):
            if not key.startswith('_') and key not in self._TO_EXCLUDE:
                self.fieldnames.append(key)
                value = getattr(self, key)
                if value:
                    self.json[key] = value

One of the lookups that provides the error is: 'AirportClinic M - MediCare Flughafen München Medizinisches Zentrum'. It returns a value, but it is the wrong location (it doesn't really find it).

Some of the json responses returns the 'bounds' if it is an exact lookup and then there is no error.

@ebreton
Copy link
Collaborator

ebreton commented Sep 14, 2017

Should be fixed with PR #293.

Could you check that it solves all your issues ? (with the branch fix_opencage)

@nyejon
Copy link
Contributor Author

nyejon commented Sep 15, 2017

Thanks for the effort. It unfortunately still has an error:
With lookup again of:
'AirportClinic M - MediCare Flughafen München Medizinisches Zentrum'

Traceback (most recent call last):
  File "<console>", line 1, in <module>

  File "..\utils.py", line 11, in get_coordinates
    opencage = geocoder.opencage(address, key=settings.OPENCAGE_API_KEY, countrycode=country, language='de', no_annotations=1)
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\api.py", line 367, in opencage
    return get(location, provider='opencage', **kwargs)
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\api.py", line 175, in get
    return options[provider][method](location, **kwargs)
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\base.py", line 407, in __init__
    self._initialize()
  File "..s\geocoder-1.32.1-py3.6.egg\geocoder\base.py", line 462, in _initialize
    self._parse_results(json_response)
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\base.py", line 522, in _parse_results
    self.add(self.one_result(json_dict))
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\opencage.py", line 23, in __init__
    super(OpenCageResult, self).__init__(json_content)
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\base.py", line 65, in __init__
    self._parse_json_with_fieldnames()
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\base.py", line 122, in _parse_json_with_fie
    value = getattr(self, key)
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\opencage.py", line 372, in bbox
    return BBox.factory([south, west, north, east]).as_dict
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\location.py", line 163, in factory
    return cls(bbox=arg)
  File "..\geocoder-1.32.1-py3.6.egg\geocoder\location.py", line 175, in __init__
    self.west, self.south, self.east, self.north = map(float, bbox)
TypeError: float() argument must be a string or a number, not 'NoneType'

@ebreton
Copy link
Collaborator

ebreton commented Sep 15, 2017

I should have added a test case for this call ...

it now passes on my side. Could you check again ?

@ebreton
Copy link
Collaborator

ebreton commented Sep 17, 2017

Merged into master by Denis 👍

@ebreton ebreton closed this as completed Sep 17, 2017
@nyejon
Copy link
Contributor Author

nyejon commented Sep 18, 2017

Thanks, tested this morning and all seems to be working again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants