apod-api icon indicating copy to clipboard operation
apod-api copied to clipboard

API returns 404 "No data available" when asking for latest date

Open jtbandes opened this issue 5 years ago • 12 comments
trafficstars

When I make an API call to https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY right now (Thu, 01 Oct 2020 01:30:49 GMT) I get a 404:

{
  "code": 404,
  "msg": "No data available for date: 2020-10-01",
  "service_version": "v1"
}

It’s currently Sep 30 in my time zone, not Oct 1. I understand if the server wants to give me Oct 1’s image after midnight UTC, but if so it shouldn’t give me a 404.

I suspect that's because the "current date" default sometimes changes before the image is actually made available (due to time zone differences, maybe?):

https://github.com/nasa/apod-api/blob/a434768b5a3d5f4ecd40adeadb1f2db3daf2ec16/application.py#L127-L129

However it looks like there is already some code to handle this. So I guess that's not working properly:

https://github.com/nasa/apod-api/blob/a434768b5a3d5f4ecd40adeadb1f2db3daf2ec16/apod/utility.py#L263-L271

jtbandes avatar Oct 01 '20 01:10 jtbandes

I'm having this issue right now

gumbarros avatar Oct 01 '20 01:10 gumbarros

Yeah, it happens every evening when the date changes. (Edit: at least I've noticed it for a couple days in the past week.)

jtbandes avatar Oct 01 '20 02:10 jtbandes

I’ve never had it happen like this.

ibll avatar Oct 01 '20 04:10 ibll

Client-side solution:

https://github.com/gumbarros/kepler/blob/master/lib/src/services/api/api.dart#L38

gumbarros avatar Oct 11 '20 10:10 gumbarros

My workaround (above) is to request a date range starting from yesterday and using the last item in the returned list. I don't include the end_date because an end_date of tomorrow returns a 400 error 😕

jtbandes avatar Oct 13 '20 00:10 jtbandes

I had been wondering about this myself. Found it when my code started crashing at exactly 8pm EDT. I assumed it was intentional but couldn't imagine why the date parameter, when left out, defaulted to "today UTC" and not "most recent valid date". Would certainly make things easier for users.

nwunderly avatar Oct 18 '20 02:10 nwunderly

I'm using the APOD API in Cypht (https://github.com/jasonmunro/cypht) and found it morning, that there was no new picture at 04:30am CET but at 06:30am - after a quick glance at nasa.gov it seems that they format all their times in EST/EDT. I have now changed the module to just calculate what day it is in EST - and just not request the "current" day my server has. A quick mail to Robert Nemiroff (one of the creators of APOD) confirmed this idea. So my guess is, that this is by design and won't be fixed - even though I think that providing the "next" day would do no harm. Just as a reminder, the archive accessible at https://apod.nasa.gov/apod/archivepix.html also doesn't list the next day and guessing the URL of the next day results in a 404 - so the whole APOD would need to be prepared for always providing the next day information.

kmpoppe avatar Mar 05 '21 21:03 kmpoppe

@kmpoppe I'm doing the same in a wrapper I'm preparing . Seems to be the only plausible solution :/

elementh avatar Mar 05 '21 22:03 elementh

@elementh I've linked my PR for the Cypht project. Maybe you can find some inspiration there.

kmpoppe avatar Mar 05 '21 22:03 kmpoppe

@kmpoppe I will, thank you very much!

elementh avatar Mar 05 '21 22:03 elementh

#51 should have fixed this issue, no?

nwunderly avatar Mar 05 '21 22:03 nwunderly

but that means having specific code to handle a whatever means "today" for the user and erase that from the request.

#51 It's helpful but can still can't handle every case.

elementh avatar Mar 05 '21 23:03 elementh