Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- ip = '8.8.8.8'
- try:
- with requests.get('https://ipapi.co/8.8.8.8/json/') as r:
- data = r.json() # получаем JSON, метод сразу переводит в нативный тип Python dict
- """
- {'ip': '8.8.8.8',
- 'city': 'Mountain View',
- 'region': 'California',
- 'region_code': 'CA',
- 'country': 'US',
- 'country_code': 'US',
- 'country_code_iso3': 'USA',
- 'country_capital': 'Washington',
- 'country_tld': '.us',
- 'country_name': 'United States',
- 'continent_code': 'NA',
- 'in_eu': False,
- 'postal': 'Sign up to access',
- 'latitude': 'Sign up to access',
- 'longitude': 'Sign up to access',
- 'timezone': 'America/Los_Angeles',
- 'utc_offset': '-0700',
- 'country_calling_code': '+1',
- 'currency': 'USD',
- 'currency_name': 'Dollar',
- 'languages': 'en-US,es-US,haw,fr',
- 'country_area': 9629091.0,
- 'country_population': 310232863.0,
- 'message': 'Please message us at ipapi.co/trial for full access',
- 'asn': 'AS15169',
- 'org': 'GOOGLE'}"""
- country = data.get('country', None) #- > US
- print(country == 'US')
- except Exception as e:
- print(repr(e), '\nДваааааащ ни работает!!!!!!!!!!!!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement