From 7a3bb5c144801cd57363d9eabeb02b358e74e4a2 Mon Sep 17 00:00:00 2001 From: Insomnia731 <120348762+Insomnia731@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:43:16 +0300 Subject: [PATCH] Update start_main.py --- start_main.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/start_main.py b/start_main.py index 32d2fe4..6ea6aa3 100644 --- a/start_main.py +++ b/start_main.py @@ -8,21 +8,15 @@ async def get_ip_info(): try: async with aiohttp.ClientSession() as session: - async with session.get("https://ipinfo.io") as response: - print(f"Response status: {response.status}") - content_type = response.headers.get('Content-Type') - print(f"Content-Type: {content_type}") - - if response.status == 200 and 'application/json' in content_type: - data = await response.json() - ip = data.get('ip') - city = data.get('city') - country = data.get('country') - print(f"IP: {ip}") - print(f"Location: {city}, {country}") - else: - error_text = await response.text() - print(f"Error: {response.status}, {error_text}") + async with session.get("https://ipinfo.io/json") as response: + data = await response.json() + + ip = data.get('ip') + city = data.get('city') + country = data.get('country') + + print(f"IP: {ip}") + print(f"Location: {city}, {country}") except Exception as e: print(f"Error: {e}")