geocoder icon indicating copy to clipboard operation
geocoder copied to clipboard

ip.ok is providing wrong value

Open jabir-khan opened this issue 3 years ago • 2 comments

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.

jabir-khan avatar Aug 05 '22 03:08 jabir-khan

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.

interDist avatar Aug 30 '22 09:08 interDist

Gotcha! great thanks.

jabir-khan avatar Aug 30 '22 13:08 jabir-khan