checkout Using OpenWeatherMap API gives 401 error here you will find some reasons why your apikey is not working. also, it takes 2 hours for key activation.

Answer from Ninad7N on Stack Overflow
🌐
Home Assistant
community.home-assistant.io › configuration
Openweathermap api key still not valid after 12 hours - Configuration - Home Assistant Community
August 31, 2022 - I am attempting to integrate openweathermap. I have an openweather account and have selected one call apu 3.0. All went well and I now have both a default api key on my account plus one I created for Homeassistant. I realise the suggestion is it takes up to 2 hours for the api key to be available in HA.
Discussions

Openweathermap APIKey not accepted - Home Assistant Community
Hello n I have been running perfectly Openweathermap in my HA for so long . Today I received a notification that OWM 2.5 is deprecated and i should move to 3.0 …fine I deleted the 2.5 integration and added the OWM 3.0 On the configuration screen I added a newly generated APIKEY from OWM i ... More on community.home-assistant.io
🌐 community.home-assistant.io
0
June 6, 2024
OpenWeatherMap invalid API key with newly created key
The problem Since 2024.6 I have issues with this integration. First there was an issue about the API version, then language. I deleted the integration, created a new API key (here: https://home.ope... More on github.com
🌐 github.com
5
May 30, 2024
Invalid API key error for Open Weather ( free ) API error, despite using a valid key
the free weather url seems to work with your key... https://api.openweathermap.org/data/2.5/weather?q=Belgrade&appid=7b26c92417fd3678d52eac12dc870222 but you are requesting a daily forecast, maybe that's not included? More on reddit.com
🌐 r/learnpython
5
2
April 2, 2021
[SOLVED] Can't retrieve OpenWeatherMap data. Invalid API key
Dear Everyone! I have changed from Yahoo to OpenWeatherMap, because Yahoo was really unrealiable and stopped working completely in the last days. OpenWeatherMap seems good for me, I have created an account, got an API key. If I issue an API call with my key, it works perfectly. More on community.openhab.org
🌐 community.openhab.org
1
0
September 3, 2018
🌐
OpenWeatherMap
openweathermap.org › faq
Frequently Asked Questions
First, please create your account by signing up with your email, if haven't OpenWeather account yet, and find API keys in the ‘API keys’ tab. Second, on the Pricing page, click 'Subscribe' button in the "One Call API 3.0" section. Fill out a short billing form and complete your subscription. Please pay attention, that you do not need to sign up any other subscriptions to get access to the One Call API 3.0.
🌐
Home Assistant
community.home-assistant.io › t › openweathermap-apikey-not-accepted › 736715
Openweathermap APIKey not accepted - Home Assistant Community
June 6, 2024 - Hello n I have been running perfectly Openweathermap in my HA for so long . Today I received a notification that OWM 2.5 is deprecated and i should move to 3.0 …fine I deleted the 2.5 integration and added the OWM 3.0 On the configuration screen I added a newly generated APIKEY from OWM i ...
🌐
GitHub
github.com › home-assistant › core › issues › 118469
OpenWeatherMap invalid API key with newly created key · Issue #118469 · home-assistant/core
May 30, 2024 - Since 2024.6 I have issues with this integration. First there was an issue about the API version, then language. I deleted the integration, created a new API key (here: https://home.openweathermap.org/api_keys) and tried to re-add the integration.
Published   May 30, 2024
Author   TheZoker
🌐
OpenWeatherMap
openweathermap.org › appid
How to start to work with Openweather API
In case we don’t hear back from you, your API key will be suspended. You will still be able to resume your subscription by contacting our customer support team. { "cod": 429, "message": "Your account is temporary blocked due to exceeding of requests limitation of your subscription type. Please choose the proper subscription http://openweathermap.org/price" } If you do not find a reply to your questions on this page, please, look at our comprehensive FAQ or contact our customer support team.
🌐
Reddit
reddit.com › r/learnpython › invalid api key error for open weather ( free ) api error, despite using a valid key
r/learnpython on Reddit: Invalid API key error for Open Weather ( free ) API error, despite using a valid key
April 2, 2021 -

I tried to run a short program from the book Automate The Boring Stuff With Python, and, my result doesn't match the result predicted by the book. Here's the code:

import requests,json,sys

APPID ='7b26c92417fd3678d52eac12dc870222'

if len(sys.argv) < 2:
    print('Usage: getOpenWeather.py city_name, 2-letter_country_code')
    sys.exit()
location = ''.join(sys.argv[1:])

#Download the JSON data from OpenWeatherMap.org's API.
url = f'https://api.openweathermap.org/data/2.5/forecast/daily?q={location}&cnt=3&APPID={APPID}'
response = requests.get(url)
response.raise_for_status()

#Uncomment to see the raw JSON text:
#print(response.text)

#Load JSON data into a Python variable.
weatherData = json.loads(response.text)

#Print weather descriptions
w = weatherData['list']
print('Current weather in %s:'%(location))
print(w[0]['weather'][0]['main'],'-',w[0]['weather'][0]['description'])
print()
print('Tomorrow:')
print(w[1]['weather'][0]['main'],'-',w[1]['weather'][0]['description'])
print()
print('Day after tomorrow:')
print(w[2]['weather'][0]['main'],'-',w[2]['weather'][0]['description'])

The response I got was:

Traceback (most recent call last):
  File "C:\Users\Vesna\PycharmProjects\getOpenWeather.py", line 13, in <module>
    response.raise_for_status()
  File "C:\Users\Vesna\AppData\Roaming\Python\Python39\site-packages\requests\models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.openweathermap.org/data/2.5/forecast/daily?q=Belgrade,Serbia&cnt=3&APPID=7b26c92417fd3678d52eac12dc870222

Then I commented out the raise_for_status function, and added a print statement regarding the response object from the API call ( just uncommented it ), and got this instead:

{"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}
Traceback (most recent call last):
  File "C:\Users\Vesna\PycharmProjects\getOpenWeather.py", line 22, in <module>
    w = weatherData['list']
KeyError: 'list'

Both messages allude to the same perceived root cause: lack of valid API key. However, this is just not the case. According to the website I used ( open weather ), a few things could cause the given error ( 401 ): invalid API key, not enough time spent after generating your first key, and trying to access premium services. I did get a valid API key, and even generated another one just to test it out ( with no different result ), I waited hours after my first attempt, so the possibility of my key not yet having finished the process of authorization is minimal, and I've checked multiple time which API services I requested, and they were the free ones ( current weather ) ONLY.

I have no idea what could be causing this error, and would immensely appreciate it if anyone helped me out with this, if they spot or know something I don't.

Find elsewhere
🌐
openHAB Community
community.openhab.org › add-ons › bindings
[SOLVED] Can't retrieve OpenWeatherMap data. Invalid API key - Bindings - openHAB Community
September 3, 2018 - Dear Everyone! I have changed from Yahoo to OpenWeatherMap, because Yahoo was really unrealiable and stopped working completely in the last days. OpenWeatherMap seems good for me, I have created an account, got an API key. If I issue an API call with my key, it works perfectly.
🌐
GitHub
github.com › home-assistant › core › issues › 78241
OpenWeatherMap not accepting API keys · Issue #78241 · home-assistant/core
September 11, 2022 - The problem OpenWeatherMap doesn't accept API-keys. On the integrations page it says "Invalid API Key provided". The logs say: 2022-09-11 21:01:29.351 WARNING (MainThread) [homeassistant.config_entries] Config entry 'OpenWeatherMap' for ...
Author   stefanku
🌐
GitHub
github.com › cmfcmf › OpenWeatherMap-PHP-Api › issues › 46
I got API by register but not work error: Invalid API key · Issue #46 · cmfcmf/OpenWeatherMap-PHP-API
October 9, 2015 - OpenWeatherMap exception: Unknown fatal error: OpenWeatherMap returned the following json object: Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.
Author   munkh-altai
🌐
Universal Devices
forum.universal-devices.com › home › plugins › polyglot v3 (pg3x) › openweathermap › invalid api key
Invalid API key - OpenWeatherMap - Universal Devices Forum
July 14, 2023 - I'm getting an error 401 that my API key is incorrect but when I use the same key for a request like: api.openweathermap.org/data/2.5/weather?q=denver,us&appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx It works fine. Is the "onecall" api not allowed for free accounts? Here' the log 2023-07-06 22:19:48,2...
🌐
Stack Overflow
stackoverflow.com › questions › 66216446 › openweathermap-api-invalid-api-key-error-error401
openweathermap api invalid api key error [error401]
when I console.log() the url it works perfectly, yet the error appears in the get request: ... Tell me you didn’t share your private key. ... ok.. basically what he's saying is.. the api key u were given isn't something u shud put up here.. I SUGGEST U CHANGE IT cuz not everyone has hearts like us
🌐
YouTube
youtube.com › sagar s (vishal)
Invalid API key - openweathermap.org error fixed - YouTube
My GearCamera - http://amzn.to/2tVwcMPTripod - http://amzn.to/2tVoceRLens - http://amzn.to/2vWzIUCMicrophone - http://amzn.to/2v9YC5pLaptop - http://amzn.t...
Published   April 22, 2021
Views   36K
🌐
WordPress
wordpress.org › support › topic › openweathermap-free-api-not-working
openweathermap free API not working | WordPress.org
August 30, 2024 - The following link worked perfectly fine using my free openweathermap API key. api.openweathermap.org/data/2.5/weather?q=my-city-name&APPID=my-API-Key But i get 401 errors all over when i try to test your plugin with the free API key of openweathermap. So the question is, does this plugin work with openweathermap free? It does not look like it to me.
🌐
freeCodeCamp
forum.freecodecamp.org › code feedback
API key not working? - Code Feedback - The freeCodeCamp Forum
October 14, 2016 - Made an account, got the API key, stuck it on the end of the url, but still getting a 401 error. Here's the link. Feel like that should be working.
🌐
openHAB Community
community.openhab.org › add-ons › bindings
OpenWeatherMap OneCall Invalid API-Key - Bindings - openHAB Community
August 21, 2022 - Hi, I have a Openhab3 installation and tried to integrate the OpenWeatherMap Binding to read information using the OneCall API. I Subscribed to the OneCall Plan on their website and I am also able to receive data using the API call with a created key: https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude={part}&appid= Openhab Things Creation: Bridge openweathermap:weather-api:api "OpenWeatherMap Account OneCall" [apikey="XXXXXXXXXXXXXXXXXXXX", refreshInterval=30, lang...
🌐
G.Calpoly
grandavehousing.calpoly.edu › blog › openweathermap-api-key-issues-troubleshooting-guide-1764801308
OpenWeatherMap API Key Issues? Troubleshooting Guide
December 3, 2025 - Let’s dive a bit deeper into two critical aspects that often cause headaches when your OpenWeatherMap API key isn’t working: activation and usage limits. When you first sign up and generate an API key on OpenWeatherMap, it’s not always immediately ready to go.
Top answer
1 of 11
23

The docs open by telling you that you need to register for an API key first.

To access the API you need to sign up for an API key

Since your url doesn't contain a key, the site tells you you're not authorized. Follow the instructions to get a key, then add it to the query parameters.

http://api.openweathermap.org/data/2.5/forecast/daily?APPID=12345&q=...
2 of 11
12

Error: Invalid API key. Please see http://openweathermap.org/faq#error401 for more info

API calls responds with 401 error: You can get the error 401 in the following cases:

  • You did not specify your API key in API request.
  • Your API key is not activated yet. Within the next couple of hours, it will be activated and ready to use.
  • You are using wrong API key in API request. Please, check your right API key in personal account.
  • You have free subscription and try to get access to our paid services (for example, 16 days/daily forecast API, any historical weather data, Weather maps 2.0, etc). Please, check your tariff in your personal account.

here are some steps to find problem.

1) Check if API key is activated

some API services provide key information in dashboard whether its activated, expired etc. openWeatherMap don't. to verify whether your key is working 'MAKE API CALL FROM BROWSER' api.openweathermap.org/data/2.5/weather?q=peshawar&appid=API_key

replace API_key with your own key, if you get data successfully then your key is activated otherwise wait for few hours to get key activated.

2) Check .env for typos & syntax

.env is file which is used to hide credentials such as API_KEY in server side code. make sure your .env file variables are using correct syntax which is NAME=VALUE

API_KEY=djgkv43439d90bkckcs

no semicolon, quotes etc

3) Check request URL

check request url where API call will be made , make sure

  • It doesn't have spaces, braces etc
  • correct according to URL encoding
  • correct according to API documentation

4) Debug using dotenv:

to know if you dotenv package is parsing API key correctly use the following code

const result = dotenv.config()

if (result.error) {
  throw result.error
} 
console.log(result.parsed)

this code checks if .env file variables are being parsed, it will print API_KEY value if its been parsed otherwise will print error which occur while parsing.

Hopefully it helps :)