Repository: pyscript/pyscript

Issue #257: Provide a better error if <py-env> paths is used in a local HTML file
Created: 2022-05-06T13:02:18Z
paths: can only be used if the page is being served out of a webserver, but not out of an HTML page on the filesystem.
This is for good reasons and it's related to #179, but currently py-script fails in a very obscure way and the page just looks broken to the user. This is the full traceback as seen in chrome's console:
Access to fetch at 'file:///home/antocuni/anaconda/pyscript/pyscriptjs/examples/utils.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.

utils.py:1          Failed to load resource: net::ERR_FAILED

pyodide.asm.js:14 Uncaught (in promise) PythonError: Traceback (most recent call last):
  File "/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.10/asyncio/tasks.py", line 234, in __step
    result = coro.throw(exc)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 500, in eval_code_async
    await CodeRunner(
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 353, in run_async
    await coroutine
  File "<exec>", line 4, in <module>
  File "/lib/python3.10/site-packages/pyodide/http.py", line 231, in pyfetch
    url, await _jsfetch(url, to_js(kwargs, dict_converter=Object.fromEntries))
  File "/lib/python3.10/asyncio/futures.py", line 284, in __await__
    yield self  # This tells Task to wait for completion.
  File "/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup
    future.result()
  File "/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception
JsException: TypeError: Failed to fetch

    at new_error (pyodide.asm.js:14:238191)
    at pyodide.asm.wasm:0xedbcb
    at pyodide.asm.wasm:0xf1a0e
    at method_call_trampoline (pyodide.asm.js:14:238105)
    at pyodide.asm.wasm:0x134c2c
    at pyodide.asm.wasm:0x217a84
    at pyodide.asm.wasm:0x174a14
    at pyodide.asm.wasm:0x135149
    at pyodide.asm.wasm:0x135243
    at pyodide.asm.wasm:0x1352e6
    at pyodide.asm.wasm:0x1fff83
    at pyodide.asm.wasm:0x1f98b5
    at pyodide.asm.wasm:0x135329
    at pyodide.asm.wasm:0x201f1b
    at pyodide.asm.wasm:0x1ff9ff
    at pyodide.asm.wasm:0x1f98b5
    at pyodide.asm.wasm:0x135329
    at pyodide.asm.wasm:0xf16d8
    at Object.Module.callPyObjectKwargs (pyproxy.gen.ts:360:23)
    at Object.Module.callPyObject (pyproxy.gen.ts:384:17)
    at wrapper (pyodide.asm.js:14:205222)

We should intercept this error and show the user a clear message and a link to some documentation which explains the issue and how to solve/mitigate it.
There are many open issues which are all related to this problem, e.g.:
#220
#217
#221

Duplicate issue #220: to do list demos do not work out of the box
Created: 2022-05-05T07:38:15Z
Here's the video
https://youtu.be/5AcN-PuvRWU

Closing comment (2022-05-06T13:10:50Z): Yes, the problem is that VS Code opens the file directly from the filesystem. If you serve the file from a webserver (either in production or a local development webserver) the example work.
Duplicate of #257, which explains better the issue and shows a workaround.