Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 401 HTTP-code with widget weather-forecast #621

Closed
4 tasks done
Himlol opened this issue Apr 29, 2022 · 7 comments
Closed
4 tasks done

[BUG] 401 HTTP-code with widget weather-forecast #621

Himlol opened this issue Apr 29, 2022 · 7 comments
Assignees
Labels
🐛 Bug [ISSUE] Ticket describing something that isn't working

Comments

@Himlol
Copy link

Himlol commented Apr 29, 2022

Environment

Self-Hosted (Docker)

Version

2.0.7

Describe the problem

Hello,

I think I've found a bug in using the openweathermap API (api.openweathermap.org) or the API's behavior has changed.

Problem:

I created a widget with weather-forecast and got 401 HTTP-code, where app try to send request.
image

Widget configuration in conf.yml looks like:

sections:
- name: Today
  icon: far fa-calendar-day
  widgets:
  - type: weather-forecast
    options:
      apiKey: <API_KEY>
      numDays: 6
      city: London
      units: metric

On Network tabs i see request like:

image

Then i try repeat request with curl and it's really response 401:

curl -v "https://api.openweathermap.org/data/2.5/forecast/daily?q=London&cnt=3&units=metric&appid=<API_KEY>" -o /dev/null

> GET /data/2.5/forecast/daily?q=London&cnt=3&units=metric&appid=<API_KEY>
HTTP/1.1
> Host: api.openweathermap.org
> User-Agent: curl/7.68.0
> Accept: */*
>

< HTTP/1.1 401 Unauthorized
< Server: openresty
< Date: Fri, 29 Apr 2022 11:07:14 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 107
< Connection: keep-alive
< X-Cache-Key: /data/2.5/forecast/daily?cnt=3&q=london,us&units=metric
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: GET, POST

But if try send request without daily, it's works fine:

curl -v "https://api.openweathermap.org/data/2.5/forecast/?q=London&cnt=3&units=metric&appid=<API_KEY>" -o /dev/null

> GET /data/2.5/forecast/?q=London&cnt=3&units=metric&appid=<API_KEY>
 HTTP/1.1
> Host: api.openweathermap.org
> User-Agent: curl/7.68.0
> Accept: */*
>

< HTTP/1.1 200 OK
< Server: openresty
< Date: Fri, 29 Apr 2022 11:08:36 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 1389
< Connection: keep-alive
< X-Cache-Key: /data/2.5/forecast/?cnt=3&q=london&units=metric
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Methods: GET, POST

Maybe I missed something, but it looks like an invalid API request. Hope for your update)

Additional info

No response

Please tick the boxes

@Himlol Himlol added the 🐛 Bug [ISSUE] Ticket describing something that isn't working label Apr 29, 2022
@liss-bot

This comment was marked as outdated.

@Lissy93
Copy link
Owner

Lissy93 commented Apr 29, 2022

Hmm, that's weird, I tried with that exact config and it seems to be working fine for me.
Could it maybe be your API key?

@Lissy93
Copy link
Owner

Lissy93 commented Apr 29, 2022

Will invalidate this key in a few hours, but here is a temporary dev API key you can try.

6e29c7d514cf890f846d58178b6d418f

If that works, we know the issue was with the key you were using. If it still doesn't work, I can try and look into it further

@Lissy93
Copy link
Owner

Lissy93 commented Apr 29, 2022

I think I see the issue. You're using a standard API key, which works fine for the daily weather, but not for the forecast. I maybe didn't make that clear enough in the docs.

ULPT: You can get a free, premium API key by filling in this form. It's a student plan, but there's no verification to check that you are still a student.

Todo

  • It does look like a 7-day forecast is now supported under OWM's One Call API, but it doesn't accept city name, only lat & lon. I could push an update that allows you to specify location as coordinates to use the free endpoint.
  • In the meantime, I've updated the troubleshooting guide with this error

@Himlol
Copy link
Author

Himlol commented Apr 29, 2022

Hello.
Thanks for the prompt feedback.

Yes, you are right, everything worked successfully with a temporary key.
In this case I'll use the free premium API key for forecast.

Thank you very much for your help.

@dazaesk
Copy link

dazaesk commented Oct 26, 2022

Hi Lissy93,
I'm having the same issue with my API. When trying to setup the student account, it appears they have changed their requirements. Please see what they say as of today (10/26/2022):
How to obtain access to the Free Data for Students

If you are a student or a university scholar, you may obtain access to these packages by doing the following:

[Sign up](https://home.openweathermap.org/users/sign_up?student=true) using your school-issued email or [login](https://home.openweathermap.org/users/sign_in?student=true) to OpenWeather using an existing OpenWeather account.
(No credit card or payment information required)

After a successful registration, you will be transferred to the student form automatically. Please, prepare the following information to fill in the form:
    Full name and the name of educational institution
    Student ID and its expiration date
    Your project description (please note, that a more thorough description of your project would facilitate the processing of your application)

Once you submit the student form, your application will be taken for validation. You will receive an email as a confirmation of the student access activation.

Here are two links, one working (without /daily), one not working (yours with /daily). I am currently on the free API plan. If you could remove the /daily from the generated API, then it should work for users on the free plan without a need to sign up for a student plan.

https://api.openweathermap.org/data/2.5/forecast?q=Rogers,AR,US&cnt=5&units=imperial&appid=1208f....30dd
https://api.openweathermap.org/data/2.5/forecast/daily?q=Rogers,AR,US&cnt=5&units=imperial&appid=1208f....30dd

I don't use Github, so if I've done something wrong, please let me know. I'll try to learn an do better next time.

Thanks,
Damon

@smeisner
Copy link

I agree with @dazaesk in that if the "/daily" was dropped from the URL, there would be no need to request the student API key. I already have an OpenWeatherMap account with a free API key and would like to use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug [ISSUE] Ticket describing something that isn't working
Projects
None yet
Development

No branches or pull requests

5 participants