fermyon / spin-python-sdk

Spin SDK for Python
https://developer.fermyon.com/spin/v2/python-components
Apache License 2.0
31 stars 11 forks source link

how to read files #88

Closed MominIqbal-1234 closed 7 months ago

MominIqbal-1234 commented 7 months ago

Traceback (most recent call last): File "/1/spin_sdk/http/init.py", line 88, in handle File "/0/app.py", line 7, in handle_request FileNotFoundError: [Errno 44] No such file or directory: 'myfile.txt'

this file is available in the same directory

agardnerIT commented 7 months ago

I'm hitting this too. I've added:

[component.blah]
source = "app.wasm"
files = [{ source = "", destination = "/" }]

Then:

def read_file():
    with open(file="index.html", mode="r") as f:
        return f.read()
dicej commented 7 months ago

Thanks for reporting this. I'm planning to look into it on Tuesday.

MominIqbal-1234 commented 7 months ago

spin.toml:

[component.myapi] source = "app.wasm" files = [{ source = "", destination = "/" }]

app.py :

from spin_sdk import http
from spin_sdk.http import Request, Response, send

class IncomingHandler(http.IncomingHandler): def handle_request(self, request: Request) -> Response: with open(file="index.html", mode="r") as f: html = f.read() print(html) return Response(200, {"content-type": "text/plain"}, bytes(f"Hello World", "utf-8"))

Error :

mefizapi: http://127.0.0.1:3000 (wildcard) Traceback (most recent call last): File "/1/spin_sdk/http/init.py", line 88, in handle File "/0/app.py", line 7, in handle_request FileNotFoundError: [Errno 44] No such file or directory: 'index.html'

image

dicej commented 7 months ago

I have a fix for this, but it requires changes to wasi-libc, componentize-py, and spin-python-sdk, so it will take some time to roll out. I'm currently waiting for GitHub Actions to build my temporary fork of wasi-sdk (which includes the wasi-libc patch). Once that's done, I'll make a componentize-py 0.13.1 release, and once that's done, I'll make a new spin-python-sdk release with the fix.

MominIqbal-1234 commented 7 months ago

thanks so much, i am waiting release :)

dicej commented 7 months ago

This should be fixed in v3.0.0, which I just released: https://pypi.org/project/spin-sdk/3.0.0/