OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PyScript <script type="py-editor"> Error Unable to use SharedArrayBuffer due insecure environment

  • Thread starter Thread starter Leonard Alphonso
  • Start date Start date
L

Leonard Alphonso

Guest
I'm using PyScript to run a simple Python script in my HTML file to display a pandas DataFrame. However, after loading the page in browser and clicking the run button of the code block I'm encountering an error related to SharedArrayBuffer due to an insecure environment.

If I run any code directly from it works perfectly. Its Only when I try to run the code from the code block it throws me an error.

Environment:


  • Running the application locally using VSCode Live Server.


  • PyScript version: 2024.6.2


  • Python library: pandas

Steps to Reproduce:


  1. Create an HTML file with the below code.


  2. Open the HTML file.


  3. run the py-editor code block


  4. Observe the error in the browser console.

Question:

How can I resolve this SharedArrayBuffer issue when running PyScript? image of the error

Below is my HTML code:

Code:
<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <link rel="stylesheet" href="https://pyscript.net/releases/2024.6.2/core.css">
        <script type="module" src="https://pyscript.net/releases/2024.6.2/core.js"></script>

        <style>
            #loading { outline: none; border: none; background: transparent }
        </style>

        <script type="module">
            const loading = document.getElementById('loading');
            addEventListener('py:ready', () => loading.close());
            loading.showModal();
        </script>
        
        <py-config>
            packages = ["pandas"]
        </py-config>
    </head>

    <body>
        <dialog id="loading">
            <h1>Loading...</h1>
        </dialog>

        <script type="py-editor">df</script>

        <script type="py">
            import pandas as pd
            data = {
                'Name': ['Alice', 'Bob', 'Charlie'],
                'Age': [25, 30, 35],
                'City': ['New York', 'Los Angeles', 'Chicago']
            }
            df = pd.DataFrame(data)
        </script>

    </body>
</html>

UPDATE

So I made some progress. I used the mini-coi script and was able to run the code from the py-editor (AKA py-REPL) without the SharedArrayBuffer error but now it's not able to access the data frame that I created using the script type="py".

This is the error: Error: Traceback (most recent call last): File "/lib/python312.zip/_pyodide/_base.py", line 574, in eval_code_async await CodeRunner( File "/lib/python312.zip/_pyodide/_base.py", line 394, in run_async coroutine = eval(self.code, globals, locals) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1, in NameError: name 'df' is not defined
<p>I'm using PyScript to run a simple Python script in my HTML file to display a pandas DataFrame. However, after loading the page in browser and clicking the run button of the code block I'm encountering an error related to <code>SharedArrayBuffer</code> due to an insecure environment.</p>
<p>If I run any code directly from it works perfectly. Its Only when I try to run the code from the code block it throws me an error.</p>
<p><strong>Environment:</strong></p>
<ul>
<li><p>Running the application locally using VSCode Live Server.</p>
</li>
<li><p>PyScript version: 2024.6.2</p>
</li>
<li><p>Python library: pandas</p>
</li>
</ul>
<p><strong>Steps to Reproduce:</strong></p>
<ol>
<li><p>Create an HTML file with the below code.</p>
</li>
<li><p>Open the HTML file.</p>
</li>
<li><p>run the py-editor code block</p>
</li>
<li><p>Observe the error in the browser console.</p>
</li>
</ol>
<p><strong>Question:</strong></p>
<p>How can I resolve this <code>SharedArrayBuffer</code> issue when running PyScript? <a href="https://i.sstatic.net/r4IYCNkZ.png" rel="nofollow noreferrer">image of the error</a></p>
<p>Below is my HTML code:</p>
<pre><code><!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="https://pyscript.net/releases/2024.6.2/core.css">
<script type="module" src="https://pyscript.net/releases/2024.6.2/core.js"></script>

<style>
#loading { outline: none; border: none; background: transparent }
</style>

<script type="module">
const loading = document.getElementById('loading');
addEventListener('py:ready', () => loading.close());
loading.showModal();
</script>

<py-config>
packages = ["pandas"]
</py-config>
</head>

<body>
<dialog id="loading">
<h1>Loading...</h1>
</dialog>

<script type="py-editor">df</script>

<script type="py">
import pandas as pd
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'Los Angeles', 'Chicago']
}
df = pd.DataFrame(data)
</script>

</body>
</html>
</code></pre>
<p><strong>UPDATE</strong></p>
<p>So I made some progress. I used the mini-coi script and was able to run the code from the py-editor (AKA py-REPL) without the SharedArrayBuffer error but now it's not able to access the data frame that I created using the script type="py".</p>
<p>This is the error:
Error: Traceback (most recent call last):
File "/lib/python312.zip/_pyodide/_base.py", line 574, in eval_code_async
await CodeRunner(
File "/lib/python312.zip/_pyodide/_base.py", line 394, in run_async
coroutine = eval(self.code, globals, locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1, in
NameError: name 'df' is not defined</p>
Continue reading...
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top