sudden fetch / CORS error

I have needed to fetch data from an API and when I originally tried to fetch the data using the API URL, I would get an error: “TypeError: Failed to fetch”. I was told to try adding a CORS proxy to the beginning of the URL, which then made it work. Everything in my notebook was working well for about a day or so but now when I open my notebook, there is another error in all the cells where I am trying to fetch data: “SyntaxError: Unexpected token ‘S’, “See /corsd”… is not valid JSON”. When I remove the CORS proxy, it just gives me the “TypeError: Failed to fetch” message.

Here is a link to one of my notebooks where I’m having this problem: ACIS Seasonal Graphics Generator / Kaitlyn Weber / Observable.

The weird thing is I am seeing these error messages in other people’s notebooks that are also using fetch… So it’s not just affecting my notebook. Here is a link to someone else’s notebook where I see the same issues:

Does anyone have any recommendations?

Thank you!

P.S. When I go to inspect the page, I clicked on the Network tab and saw that the fetch errors have a status code of 403. Not sure if that info is helpful but wanted to include, just in case.

1 Like

It’s generally a good idea to include a link to your notebook so that folks can experiment with it to diagnose the problem. If I did have the link, the first thing I’d try would be a different CORS proxy to see if you’re dealing with an intermittent problem with cors-anywhere, which is not really meant to be a production CORS proxy. My first choice would be corsproxy.io.

2 Likes

Thank you! This is my first post ever on a discussion board like this so I appreciate the guidance :slight_smile:

I have added the URL to one of my notebooks that was working until yesterday as well as someone else’s notebook that also has the same errors. I had used this dropdown from another notebook that allows you to select one of three CORS options. The first two options give me: “TypeError: Failed to fetch” then the last option (herokuapp) gives me: " SyntaxError: Unexpected token ‘S’, “See /corsd”… is not valid JSON" which is what I see on a lot of other notebooks too.

1 Like

It looks to me like the following works:

data = fetch(
  `https://corsproxy.io/?http://data.rcc-acis.org/StnData?params={"sid":"ABIthr","sdate":"1970-02-28","edate":"2022-02-28","elems":[{"name":"avgt","interval":[1,0,0],"duration":"std","season_start":"12-01","reduce":"mean","maxmissing":9}]}`
).then((r) => r.json())
1 Like

Yes! It does. Thank you very much!

1 Like