DenisCarriere / geocoder

:earth_asia: Python Geocoder
http://geocoder.readthedocs.org
MIT License
1.62k stars 286 forks source link

ip.ok is providing wrong value #453

Open jabir-khan opened 2 years ago

jabir-khan commented 2 years ago

hey I was just doing stuff with geocoder and I reeally loved it. However I guess there is some issue in it here is the details:

Screen Shot 2022-08-05 at 8 27 53 AM

As you can see ip.ok is giving True but ip.json.["ok"] is returning False which doesnot satisfy this statement "If geocoder was able to contact the server, but no result could be found for the given search terms, the ok attribute on the returned object will be False." from the docs.

interDist commented 2 years ago

That is because the ok property on the return value tells you (as the docs say) if there is any result, but the IpInfo provider is coded to treat any response from the service as a “result”. It does look like the _adapt_results hook of IpinfoQuery incorrectly processes the response, but it is probably not going to be fixed anytime soon. Our only option is to check both values:

    info = geocoder.ip( ... )
    if info.ok and info.current_result.ok:
        # This means the server could be contacted AND info about the IP could be fetched.
jabir-khan commented 2 years ago

Gotcha! great thanks.