DiscoverDharsan Decodes Data(Eng) S5 E4.2. Python essentials for DE II
(Eng) S5 E4.2. Python essentials for DE II

(Eng) S5 E4.2. Python essentials for DE II

Update: 2026-01-30
Share

Description

import requests


url = "https://api.weather.com/v1/current" # Example URL


try:

response = requests.get(url, timeout=5) # Stop waiting after 5 seconds

response.raise_for_status() # Automatically trigger an error if status isn't 200

data = response.json()

print("Data fetched successfully!")

except requests.exceptions.HTTPError as err:

print(f"The Server had an issue: {err}")

except requests.exceptions.ConnectionError:

print("The Internet is down! Checking again in 5 minutes...")

except Exception as e:

print(f"Something weird happened: {e}")



import os

from dotenv import load_dotenv

load_dotenv() # Load the secrets from the .env file

api_key = os.getenv("WEATHER_API_KEY")

print(f"Using API Key: {api_key[:4]}****") # Only print a tiny bit for safety

Comments 
loading
00:00
00:00
x

0.5x

0.8x

1.0x

1.25x

1.5x

2.0x

3.0x

Sleep Timer

Off

End of Episode

5 Minutes

10 Minutes

15 Minutes

30 Minutes

45 Minutes

60 Minutes

120 Minutes

(Eng) S5 E4.2. Python essentials for DE II

(Eng) S5 E4.2. Python essentials for DE II

Dharsan