How to get the OpenWeather API key

Share

There are several applications that require OpenWeather APIs for their underlying functions.

This Answer will walk us through the important steps we must follow to get the OpenWeather API key.

Getting the OpenWeather API key

To get the OpenWeather API key, we must follow the steps below:

  1. Click here to open the OpenWeather website.

  2. Click the “Sign in” button, as shown below:

  3. A new page opens. If you already have an account on the website, enter your credentials. Otherwise, click the “Create an Account” option.

  1. Enter your username, email, and password credentials. Make sure to check all the privacy and security agreements. You may opt to receive emails and news from OpenWeather.

  1. Once your account is ready, you are automatically directed to the OpenWeather page where you signed in. It asks you about your company, and the purpose of using the OpenWeather platform.

  1. Click on your username in the top right corner. In this case, the username is “Educative.io.” A dropdown menu appears. Click the “My API keys” option.

  1. You now have the Weather API key. Select the key and copy it.

Verify the API key

Please add your API key in the api_key field. Click the "Run" button to test whether the API key is valid.

import requests
import json
import os
api_key = os.environ["API_Key"]
url = 'http://api.openweathermap.org/data/2.5/weather?q=london&appid=' + api_key
response = requests.get(url)
if response.status_code == 200:
print('Wohoo! Setup complete!\n\nWe are good to go!')
elif response.status_code == 429:
print('Your account is temporary blocked due to exceeding of requests limitation of your subscription type. Please choose the proper subscription http://openweathermap.org/price')
else:
print(f'{response.status_code}: {response.reason}')
Copyright ©2024 Educative, Inc. All rights reserved