import requests URL = 'http://ip.taobao.com/service/getIpInfo.php' # 淘寶IP地址庫API try: r = requests.get(URL, params={'ip': '8.8.8.8'}, timeout=1) r.raise_for_status() # 如果響應狀態碼不是 200,就主動拋出異常 except requests.RequestException as e: print(e) else: result = r.json() print(type(result), result, sep='\n')
