pythonpython-3.xdjangogeoipmaxmind

Python Geoip2 maxminddb.reader error in EC2 server


Hi I am facing a issue with below code.

PS : Its working fine with my local machine but facing issues in servers.

import geoip2.database

def get_geo_city_from_ip(ip="103.148.20.109"):

    try:
        reader = geoip2.database.Reader('GeoLite2-City.mmdb')
        response = reader.city(ip)
        city=response.city.name
        reader.close()
        return city
    except Exception as e:
        return None
a = get_geo_city_from_ip()
print("City ####",a)

Error

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import geoip2.database
  File "/var/www/html/geo/test/lib/python3.5/site-packages/geoip2/database.py", line 10, in <module>
    import maxminddb
  File "/var/www/html/geo/test/lib/python3.5/site-packages/maxminddb/__init__.py", line 5, in <module>
    import maxminddb.reader
  File "/var/www/html/geo/test/lib/python3.5/site-packages/maxminddb/reader.py", line 36
    _buffer: Union[bytes, FileBuffer, "mmap.mmap"]
           ^
SyntaxError: invalid syntax

Packages & Version Python 3.5.2 aiohttp==3.6.2 async-timeout==3.0.1 attrs==20.2.0 certifi==2020.6.20 chardet==3.0.4 geoip2==4.0.2 idna==2.10 idna-ssl==1.1.0 maxminddb==2.0.2 multidict==4.7.6 pkg-resources==0.0.0 requests==2.24.0 simplegeoip2==1.0.2 typing-extensions==3.7.4.3 urllib3==1.25.10 yarl==1.5.1


Solution

  • Its working after I changed the geoip2==2.9.0 maxminddb==1.4.1