1. ods
  2. ip2cc

Commits

ods  committed 3cb16ec

Better error handling (SF bug #886888)

  • Participants
  • Parent commits d97b6f8
  • Branches default

Comments (0)

Files changed (1)

File ip2cc.py

View file
                 sys.exit(exc)
             else:
                 addr_str = '%s (%s)' % (addr, ip)
-        db = CountryByIP(db_file)
+        try:
+            db = CountryByIP(db_file)
+        except IOError, exc:
+            import errno
+            if exc.errno==errno.ENOENT:
+                sys.exit('Database not found. Run update.py to create it.')
+            else:
+                sys.exit('Cannot open database: %s' % exc)
         try:
             cc = db[ip]
         except KeyError: