0

I want to fetch json data with PyScript but cannot get over a

pyodide.ffi.JsException: TypeError: NetworkError when attempting to fetch resource.

It works with the sample data (the outcommented lines) but not with my json data which looks valid to me:

[
    {
      "name": "Maximilian Bauer",
      "birthdate": "15. Maerz 1985"
    },
    {
      "name": "Sophie Schneider",
      "birthdate": "22. Juli 1990"
    }
]
from pyscript import fetch

# response = await fetch(
#    "https://microsoftedge.github.io/Demos/json-dummy-data/64KB.json",
#    method="GET"
#).json()

response = await fetch(
    "https://www.nanobooks23.de/material/schachclub2.json",
    method="GET"
).json()

print(response)

And do I have to use fetch() from the js module or the pyscript module or doesn't it matter?

Update: The json file is served by a web server that probably does not use the "CORS-Header":

Access-Control-Allow-Origin: *

So I would have to use a "CORS-Enabled API"?

1 Answer 1

0

Its CORS of course, when I use a CORS proxy like

https://corsproxy.io/?

and put it before the url like

https://corsproxy.io/?https://www.nanobooks23.de/material/schachclub2.json

it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.