Generated Python Code:
def get_weather(city, api_key):
# Step 1: Setup authentication
headers = {'Authorization': f'Bearer {api_key}'}
# Step 2: Construct parameters
params = {'q': city, 'units': 'metric'}
# Step 3: Make request
try:
response = requests.get(URL, params=params, headers=headers, timeout=10)
response.raise_for_status()
# Step 4: Error handling (implicit in try-except)
return response.json()
except requests.RequestException as e:
raise APIError(f'Failed: {e}')