Do not spam on geoip not found errors

This commit is contained in:
Hector Martin 2021-04-03 15:43:48 +09:00
parent eeb869e553
commit 0130c51c2c

4
app.py
View File

@ -1,7 +1,7 @@
import os, zipfile, hashlib, hmac, struct, logging, random, json import os, zipfile, hashlib, hmac, struct, logging, random, json
import urllib import urllib
from io import BytesIO from io import BytesIO
import geoip2.database import geoip2.database, geoip2.errors
from logging.handlers import SMTPHandler from logging.handlers import SMTPHandler
from datetime import datetime, timedelta from datetime import datetime, timedelta
from flask import Flask, request, g, render_template, make_response, redirect, url_for from flask import Flask, request, g, render_template, make_response, redirect, url_for
@ -54,6 +54,8 @@ def region():
country = gi.country(request.remote_addr).country.iso_code country = gi.country(request.remote_addr).country.iso_code
app.logger.info("GI: %s -> %s", request.remote_addr, country) app.logger.info("GI: %s -> %s", request.remote_addr, country)
return COUNTRY_REGIONS.get(country, 'E') return COUNTRY_REGIONS.get(country, 'E')
except geoip2.errors.AddressNotFoundError:
return 'E'
except: except:
app.logger.exception("GeoIP exception") app.logger.exception("GeoIP exception")
return 'E' return 'E'