Commits

Hector Garcia  committed bac4b0e

Added try/catch for cc and region

  • Participants
  • Parent commits 125e164

Comments (0)

Files changed (1)

File localeurl/middleware.py

             except AttributeError:
                 ip = request.META.get('HTTP_X_REAL_IP', None)
             if ip is not None and ip not in settings.INTERNAL_IPS:
-                ccode = geo.city(ip)['country_code'].lower()
-                region = geo.city(ip)['region'].lower()
-                if ccode == 'es' and region == '56': # Catalunya
-                    locale = 'ca'
-                    geolocated = True
+                try:
+                    ccode = geo.city(ip)['country_code'].lower()
+                    region = geo.city(ip)['region'].lower()
+                except AttributeError:
+                    pass  # country_code and/or region missing
+                else:
+                    if ccode == 'es' and region == '56': # Catalunya
+                        locale = 'ca'
+                        geolocated = True
             if localeurl_settings.USE_ACCEPT_LANGUAGE and not geolocated:
                 accept_langs = filter(lambda x: x, [utils.supported_language(lang[0])
                                                     for lang in