When trying to load a Python script from a separate file using PyScript, I get the following error:
JsException(TypeError: Failed to fetch)
How can I fix this error and run the Python script?
My source code consists of two files, hello.html and hello.py.
hello.html:
<html>
<head>
<title>Hello PyScript</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<py-env>
- paths:
- /hello.py
</py-env>
<body>
<py-script src="./hello.py"></py-script>
</body>
</html>
hello.py:
print("Hello, PyScript!")
In the developer tools, the console displays the following error:
Access to fetch at 'file:///hello.py' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
I am opening the file by double-clicking on it in file explorer.
hello.pyto fix this CORS issue. The similar looking issue that @DataMastery and I had with download of pyscript.js was actually unrelated to this - it was fixed by the PyScript project on 13th May, the same day it was reported.