Python geoip find country using json
Question: 
    from urllib2 import urlopen
    from contextlib import closing
    import json
    import time
    import os
    
    while True:
        url = 'http://freegeoip.net/json/'
        try:
            with closing(urlopen(url)) as response:
                location = json.loads(response.read())
                location_city = location['city']
                location_state = location['region_name']
                location_country = location['country_name']
                #print(location_country)
                if location_country == "Germany":
                    print("You are now surfing from: " + location_country)
                    os.system(r'firefox /home/user/Documents/alert.html')
                        except:
            print("Could not find location, searching again...")
        time.sleep(1)   
    

Its doesn't reply any country can I get help to solve the problem?


Answer: Besides of the wrong indentation, your code looks fine.

The problem seems to be that the page itself does not respond. If you try to
open it in a browser for example, the connection gets refused.

Probably the api is either overloaded, or does no longer exist.

