django/django · error · GeoIP2Exception

Unable to handle database edition: {database_type}

Error message

Unable to handle database edition: {database_type}

What it means

Raised in GeoIP2.__init__ after opening the reader when the database's metadata.database_type is not in SUPPORTED_DATABASE_TYPES (GeoLite2-City, GeoLite2-Country, GeoIP2-City, GeoIP2-Country, DBIP-City-Lite, DBIP-Country-Lite). The wrapper only knows how to interpret City and Country editions; other MaxMind products (e.g. GeoIP2-Anonymous-IP, GeoIP2-ISP) are rejected.

Source

Thrown at django/contrib/gis/geoip2.py:120

                "GeoIP path must be provided via parameter or the GEOIP_PATH setting."
            )

        path = to_path(path)

        # Try the path first in case it is the full path to a database.
        for path in (path, path / city, path / country):
            if path.is_file():
                self._path = path
                self._reader = geoip2.database.Reader(path, mode=cache)
                break
        else:
            raise GeoIP2Exception(
                "Path must be a valid database or directory containing databases."
            )

        database_type = self._metadata.database_type
        if database_type not in SUPPORTED_DATABASE_TYPES:
            raise GeoIP2Exception(f"Unable to handle database edition: {database_type}")

    def __del__(self):
        # Cleanup any GeoIP file handles lying around.
        if self._reader:
            self._reader.close()

    def __repr__(self):
        m = self._metadata
        version = f"v{m.binary_format_major_version}.{m.binary_format_minor_version}"
        return f"<{self.__class__.__name__} [{version}] _path='{self._path}'>"

    @cached_property
    def _metadata(self):
        return self._reader.metadata()

    @cached_property
    def is_city(self):
        return "City" in self._metadata.database_type

View on GitHub (pinned to ae25a40be0)

Solutions

  1. Use a supported edition: GeoLite2/GeoIP2 City or Country, or DBIP-City-Lite/DBIP-Country-Lite
  2. If you have an enterprise mmdb, use the geoip2 library directly (geoip2.database.Reader) instead of the Django wrapper
  3. Verify the file: geoip2.database.Reader(path).metadata().database_type

Example fix

// before
GeoIP2(path='/data/GeoIP2-ISP.mmdb')
// after
GeoIP2(path='/data/GeoLite2-City.mmdb')
# or use maxmind directly for unsupported editions
import geoip2.database
reader = geoip2.database.Reader('/data/GeoIP2-ISP.mmdb')
Defensive patterns

Strategy: validation

Validate before calling

from django.contrib.gis.geoip2 import SUPPORTED_DATABASE_TYPES
import geoip2.database

def check_db_type(path):
    db_type = geoip2.database.Reader(path).metadata().database_type
    if db_type not in SUPPORTED_DATABASE_TYPES:
        raise ValueError(f'Unsupported edition: {db_type}')
    return db_type

Type guard

from django.contrib.gis.geoip2 import SUPPORTED_DATABASE_TYPES
import geoip2.database

def is_supported_db(path) -> bool:
    return geoip2.database.Reader(path).metadata().database_type in SUPPORTED_DATABASE_TYPES

Try / catch

from django.contrib.gis.geoip2 import GeoIP2Exception
try:
    g = GeoIP2(path=p)
except GeoIP2Exception as e:
    if 'database edition' in str(e):
        # fall back to using geoip2.database.Reader directly
        ...
    raise

Prevention

When it happens

Trigger: Opening a GeoIP2-ISP.mmdb, GeoIP2-Anonymous-IP.mmdb, GeoIP2-Domain.mmdb, GeoIP2-Connection-Type.mmdb, or any custom/enterprise mmdb whose database_type metadata string is not in the allowlist. Also triggered by a corrupt or placeholder mmdb whose metadata reports an unknown type.

Common situations: Subscribing to MaxMind insights and downloading the wrong product; bundling an enterprise mmdb; testing with a synthetic mmdb that has a non-standard database_type.

Related errors


AI-assisted analysis of django/django@ae25a40be0 (2026-08-06). Data as JSON: /api/errors/afe22a9b024d979b. Report an issue: GitHub.