[Fixed]-'str' object has no attribute 'META' in function when retrieving request.META

1👍

You are passing in the ip argument to geoip_country():

ip = get_ip_address(request)
ip_country = geoip_country(ip)

but your geoip_country() function expects a request:

def geoip_country(request):

which it then passes on to get_ip_address() again:

return geoDetect.country_code_by_addr(get_ip_address(request))

Change the geoip_country() function to expect an ip instead:

def geoip_country(ip):
    path = Path(__file__).ancestor(3)+"/scripts/notes/custom_packages/geoip/GeoIP.dat"
    geoDetect = pygeoip.GeoIP(path)
    return geoDetect.country_code_by_addr(ip)

Leave a comment