maxmind / GeoIP2-perl

Perl API for MaxMind's GeoIP2 web services and databases
https://metacpan.org/release/GeoIP2/
Other
18 stars 11 forks source link

zero accuracy_radius #39

Closed sezal closed 8 years ago

sezal commented 8 years ago

Code below with database from http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz fails for last couple days. The problem with accuracy_radius which is 0 for some reason.

Since accuracy_radius attribute of GeoIP2::Record::Location declared as 'PositiveInt' I would try to pre-validate data returned by reader. Zero accuracy_radius means n/a and probably it's better not to pass it to GeoIP2::Record::Location::new at all rather than changing attribute type to 'NonNegInt'

use GeoIP2::Database::Reader;

my $Geo_IP = GeoIP2::Database::Reader->new(
    file    => 'GeoLite2-City.mmdb',
    locales => [ 'en' ],
);

if( my $city_record = $Geo_IP->city( ip => '8.8.8.8' ) ) # or 217.15.91.142
{
    my $location = $city_record->location;
}

Dies with error

0 is not a valid PositiveInt

Trace begun at .../lib/perl5/GeoIP2/Types.pm line 247
GeoIP2::Types::_tc_fail(0, 'PositiveInt') called at (eval 123) line 70
eval {...} at (eval 123) line 59
GeoIP2::Record::Location::new(undef, 'time_zone', 'America/Los_Angeles', 'latitude', 37.386, 'accuracy_radius', 0, 'metro_code', 807, 'longitude', -122.0838, 'locales', 'ARRAY(0x12a4cb8)') called at .../lib/perl5/GeoIP2/Role/Model/Location.pm line 104
GeoIP2::Role::Model::Location::_build_record('GeoIP2::Model::City=HASH(0x2b1f668)', 'location', '_raw_location') called at (eval 122) line 30
GeoIP2::Model::City::location('GeoIP2::Model::City=HASH(0x2b1f668)') called at /home/sergiy/work/ts/tt/120_traffic_data/40_conversions_count.t line 17

GeoIP2: 2.003001 MaxMind::DB::Reader::XS: 1.000003

oschwald commented 8 years ago

Thanks. We just added the field to this database. It indeed should never be 0. We hope to have this fixed in the next build.

tjmather commented 8 years ago

Thanks again for reporting this. We have released an updated database on http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz which should fix the issue you raised. Does the updated database solve the issue?

sezal commented 8 years ago

confirmed. It's fixed now.