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
정보
- 프로그램
- 주기격주 업데이트
- 발행일2026년 1월 30일 오전 12:31 UTC
- 길이11분
- 등급전체 연령 사용가
