How to use pillow module in pyscript to open screenshot with the help of html onclick button?

<button id="button" type = "button" class="btn btn-primary" pys-onClick="run_python"> 
 NEXT </button>
<py-script>
 

from PIL import Image
 op = Element("output")
 def run_python(*args,**kwargs):
 image = Image.open("home/saikumar/Desktop/screenshot/selenium1.jpg"/)
 image.show()

</py-script>

i am trying to open the screenshot image which is present in my local directory with the help PIL module by clicking button but i am unable open and getting error like file not found and i have to open the screenshot by clicking NEXT button. please help through this.

Error case:

Uncaught PythonError: Traceback (most recent call last):
File "<exec>", line 4, in run_python
File "/lib/python3.10/site-packages/PIL/Image.py", line 3068, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 44] No such file or directory: 'home/saikumar/Desktop/screenshot/selenium1.jpg'

at new_error (pyodide.asm.js:14:238191)
at pyodide.asm.wasm:0xedbcb
at pyodide.asm.wasm:0xedccc
at Module._pythonexc2js (pyodide.asm.js:14:932707)
at Module.callPyObjectKwargs (pyproxy.gen.ts:374:12)
at Module.callPyObject (pyproxy.gen.ts:384:17)
at PyProxyClass.apply (pyproxy.gen.ts:1145:19)
at Object.apply (pyproxy.gen.ts:1022:18)
new_error @ pyodide.asm.js:14
$wrap_exception @ pyodide.asm.wasm:0xedbcb
$pythonexc2js @ pyodide.asm.wasm:0xedccc
Module._pythonexc2js @ pyodide.asm.js:14
Module.callPyObjectKwargs @ pyproxy.gen.ts:374
Module.callPyObject @ pyproxy.gen.ts:384
apply @ pyproxy.gen.ts:1145
apply @ pyproxy.gen.ts:1022

try adding opening / to the path and make sure, that application has permission to that directory/file. You definitely should keep apps/scripts/media/static files inside an project folder instead of looking for them from root directory of the hard drive.

image = Image.open("home/saikumar/Desktop/screenshot/selenium1.jpg")
# change to:
image = Image.open("/home/saikumar/Desktop/screenshot/selenium1.jpg")
Back to Top