Advertisement
Guest User

cURL in python

a guest
Jul 16th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. ip = '8.8.8.8'
  5. try:
  6.     with requests.get('https://ipapi.co/8.8.8.8/json/') as r:
  7.         data = r.json() # получаем JSON, метод сразу переводит в нативный тип Python dict
  8.         """
  9.        {'ip': '8.8.8.8',
  10.        'city': 'Mountain View',
  11.        'region': 'California',
  12.        'region_code': 'CA',
  13.        'country': 'US',
  14.        'country_code': 'US',
  15.        'country_code_iso3': 'USA',
  16.        'country_capital': 'Washington',
  17.        'country_tld': '.us',
  18.        'country_name': 'United States',
  19.        'continent_code': 'NA',
  20.        'in_eu': False,
  21.        'postal': 'Sign up to access',
  22.        'latitude': 'Sign up to access',
  23.        'longitude': 'Sign up to access',
  24.        'timezone': 'America/Los_Angeles',
  25.        'utc_offset': '-0700',
  26.        'country_calling_code': '+1',
  27.        'currency': 'USD',
  28.        'currency_name': 'Dollar',
  29.        'languages': 'en-US,es-US,haw,fr',
  30.        'country_area': 9629091.0,
  31.        'country_population': 310232863.0,
  32.        'message': 'Please message us at ipapi.co/trial for full access',
  33.        'asn': 'AS15169',
  34.        'org': 'GOOGLE'}"""
  35.         country = data.get('country', None) #- > US
  36.         print(country == 'US')
  37. except Exception as e:
  38.     print(repr(e), '\nДваааааащ ни работает!!!!!!!!!!!!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement