getJSON reports Not Found on valid URL

I’m having a hard time understanding why Hugo would report a Not Found from a getJSON call on a URL that does return valid json (as verified using curl on the same computer and copy/paste the url from the Hugo error message)

The error message is:
Failed to retrieve remote file: Not Found

which I assume means that Hugo is getting a 404 from the server, but as I said the URL is fine.

The server is returning content-type: application/json

Perhaps Hugo is expecting a different content-type? (Clearly I’m grasping at straws here)

It’s impossible to help without more context. What is the form of the URL in question?

Also see:

1 Like

Right you are.
Here’s a simple git repo that you should be able to clone

The source for the shortcode template that I’m using to get the data.

{{ $players := getJSON "https://4x7vplv094.execute-api.us-east-1.amazonaws.com/prod?tourney=Orleans%20Winter%20Open%202020" }}                                
<ul>
{{ range $players }}
<li>{{.player.FirstAndLast}} </li>
{{end}}
</ul>

I’ve confirmed that the URL is returning a valid JSON array using this curl command:
curl -s "https://4x7vplv094.execute-api.us-east-1.amazonaws.com/prod?tourney=Orleans%20Winter%20Open%202020" | jq '.[]|{p:.player.FirstAndLast,r:.odsaRating}'

The error message that I get from Hugo is:
Failed to get JSON resource “https://4x7vplv094.execute-api.us-east-1.amazonaws.com/prod?tourney=Orleans%20Winter%20Open%202020”: Failed to retrieve remote file: Not Found

I am getting a variety of errors when I check the JSON URL you provided with the following:

Don’t know what’s going on here. This seems like a problem with the server configuration. Maybe a firewall is interfering with the request.

1 Like

Thanks for running that down. The 404 from wget is what set me down the right path to debugging the server. The server was in fact returning the correct data, but a 404 in the header rather than 200. my curl -s was masking that 404 which the wget was not.

Thank you for your assistance.

The one suspicious thing I see is that the search term is “Orleans Winter Open 2020” with %20 meaning space int he URL. Maybe we found some kind of bug in a used URL parser that is choking on the %202020 part?

Chopping it off returns an empty json. https://4x7vplv094.execute-api.us-east-1.amazonaws.com/prod?tourney=Orleans%20Winter%20Open

We don’t know what’s going on with the “tourney” parameter. if it’s some kind of tag or marker, try setting it up without spaces and see where this lands you.

The headers look ok, so it’s not some kind of authentication thing or routing/renaming. I would think the encoded special characters in the URL make some kind of problem in one of the used parts.

… and is working via wget for instance.

I’ve fixed the server that was returning 404 even after finding the appropriate data (a list of players for the "Orleans Winter Open 2020"squash tournament (hence the %20 values in the tourney parameter (I assumed that getJson didn’t url encode the parameters?)

If you used spaces instead of %20 then yes, I think getJson forwards the spaces. Maybe have a look at urlize in your templates…

1 Like

Maybe safeURL too…

1 Like