Skip to content

Commit

Permalink
Update start_main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Insomnia731 authored Sep 22, 2024
1 parent 600cba9 commit 39b5e80
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions start_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

async def get_ip_info():
try:
async with aiohttp.ClientSession() as session:
async with session.get("https://ipinfo.io") as response:
if response.status == 200:
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:
# Получаем текст ошибки, если не 200
error_text = await response.text()
print(f"Error: {response.status}, {error_text}")
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}")
except Exception as e:
print(f"Error: {e}")

Expand Down

0 comments on commit 39b5e80

Please sign in to comment.