Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WARNING in utils: Could not determine flag for ip #176

Open
pswapneel opened this issue Jul 1, 2021 · 4 comments
Open

WARNING in utils: Could not determine flag for ip #176

pswapneel opened this issue Jul 1, 2021 · 4 comments

Comments

@pswapneel
Copy link

Started seeing this on an instance with version 1.9 so as a test I setup 1.9.1 freshly and the problem persists.

Steps to reproduce the issue,

docker-compose logs chnserver

Output(IP addresses have been truncated),

docker-compose logs chnserver Attaching to chnserver_chnserver_1 chnserver_1 | [2021-07-01 05:31:45,447] WARNING in utils: Could not determine flag for ip: chnserver_1 | [2021-07-01 05:32:05,472] WARNING in utils: Could not determine country name for ip: chnserver_1 | [2021-07-01 05:32:25,495] WARNING in utils: Could not determine flag for ip: chnserver_1 | [2021-07-01 05:32:45,519] WARNING in utils: Could not determine country name for ip: chnserver_1 | [2021-07-01 05:33:05,540] WARNING in utils: Could not determine flag for ip:

I am assuming the chnserver_chnserver_1 container is missing the geoip package ? Any help is much appreciated. Thank you.

@pswapneel
Copy link
Author

pswapneel commented Jul 1, 2021

It looks like utils.py contains the code for the geolocation.

def _get_flag_ip(ipaddr):
    """
    Returns an address where the flag is located.
    Defaults to static immge: '/static/img/unknown.png'
    """
    flag_path = url_for(
        'static', filename='img/flags-iso/shiny/64') + '/{}.png'
    geo_api = 'https://api.ipgeolocationapi.com/geolocate/{}'
    try:
        # Using threatstream's geospray API to get
        # the country code for this IP address.
        r = requests.get(geo_api.format(ipaddr))
        ccode = r.json()['un_locode']
        app.logger.debug('Found CC code: {}'.format(ccode))
    except Exception:
        app.logger.warning(
            "Could not determine flag for ip: {}".format(ipaddr))
        return url_for('static', filename=constants.DEFAULT_FLAG_URL)
    else:
        # Constructs the flag source using country code
        flag = flag_path.format(ccode.upper())
        local_flag_path = '/static/img/flags-iso/shiny/64/{}.png'.format(
            ccode.upper())

        if os.path.exists(MHN_SERVER_HOME + "/mhn"+local_flag_path):
            return flag
        else:
            return url_for('static', filename=constants.DEFAULT_FLAG_URL)

Probing further, api.ipgeolocationapi.com no longer resolves. ipgeolocationapi.com now redirects to ipapi.com

@amerck
Copy link
Contributor

amerck commented Jul 27, 2021

Currently working on tracking down a viable replacement without having to manage API keys. This fix should roll out in the next release. Thanks for bringing this to our attention!

@pswapneel
Copy link
Author

@amerck I have been fiddling with the code to see if the geoip code can be temporarily disabled so that the UI can function without it. No luck yet.

Did you get a chance to figure out an alternative? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@amerck @pswapneel and others