pygeoip
raw JSON → 0.3.2 verified Fri May 01 auth: no python deprecated
Pure Python GeoIP API for MaxMind databases. Current version 0.3.2, last released in 2017. Unmaintained, no longer recommended. Use geoip2 instead.
pip install pygeoip Common errors
error AttributeError: module 'pygeoip' has no attribute 'GeoIP' ↓
cause Importing pygeoip module incorrectly or using an older version.
fix
Use 'import pygeoip' then 'pygeoip.GeoIP' or verify installation.
error pygeoip.geoip.GeoIPError: Can't find the GeoIP database file: GeoIP.dat ↓
cause The database file is missing or path is wrong.
fix
Download GeoIP.dat from MaxMind (legacy) and specify correct path.
error ValueError: IPv6 addresses not supported ↓
cause pygeoip does not support IPv6 addresses.
fix
Convert IPv6 to IPv4 if possible, or use geoip2 library.
Warnings
deprecated pygeoip is unmaintained and will not receive updates for new MaxMind databases. Use geoip2 instead. ↓
fix pip install geoip2 and replace with geoip2.database.Reader
breaking MaxMind discontinued the legacy GeoIP.dat format starting 2019. The library only supports the legacy format. ↓
fix Use geoip2 with GeoLite2-Country.mmdb
gotcha The library does not support IPv6 addresses. Passing an IPv6 address raises an error. ↓
fix Check if address is IPv4 before lookup, or use geoip2.
Imports
- GeoIP wrong
from pygeoip import GeoIP (works but not recommended)correctimport pygeoip geoip = pygeoip.GeoIP('GeoIP.dat')
Quickstart
import pygeoip
gi = pygeoip.GeoIP('GeoIP.dat', flags=pygeoip.MEMORY_CACHE)
print(gi.country_code_by_name('google.com')) # 'US'