marimo icon indicating copy to clipboard operation
marimo copied to clipboard

interference with fastapi

Open SpielerNogard opened this issue 10 months ago • 6 comments

Describe the bug

i have 2 docker containers, one with a fastapi and one with my marimo notebook. I now try to use requests to access the API but i only get {'details':'Not found'} as a response. The request cant be found in the fastapi logs, so i assume, marimo calls something internaly ? I also tried to change the ports of my fastapi, but the behaviour is the same.

If i use a normal python script, everything works as expected, so its not a fastapi thing

Environment

{ "marimo": "0.3.8", "OS": "Darwin", "OS Version": "23.4.0", "Processor": "arm", "Python Version": "3.8.18", "Binaries": { "Browser": "123.0.6312.87", "Node": "v21.6.1" }, "Requirements": { "click": "8.1.7", "importlib-resources": "6.1.1", "jedi": "0.19.1", "markdown": "3.5.2", "pymdown-extensions": "10.7", "pygments": "2.17.2", "tomlkit": "0.12.3", "uvicorn": "0.27.0.post1", "starlette": "0.37.0", "websocket": "missing", "typing-extensions": "4.9.0", "black": "24.1.1" } }

Code to reproduce

No response

SpielerNogard avatar Apr 01 '24 15:04 SpielerNogard

can you explain a bit more about the 2 docker containers - are they running locally or on a remote VM? are they running on the same VM? when you are running them on different ports, do you expose them on the same port?

You can configure the port and host for a marimo application --port, --host.

mscolnick avatar Apr 01 '24 15:04 mscolnick

both run on the same machine. best example is: I have the fast-api docker running on port 9000. and run the marimo notebook on port 8000 (without a docker)

I now run a request.get against http://localhost:9000 (Theoreticaly my fast-api) now the response is {'detail':'Not Found'} if i run a request against an api on another server, everything works as expected. So it has something to do with the localhost

SpielerNogard avatar Apr 01 '24 16:04 SpielerNogard

it will probably interact the same, if i dont use any docker at all let me try that

SpielerNogard avatar Apr 01 '24 16:04 SpielerNogard

yes the same behaviour happens if i dont use any docker at all

fast-api on 9000 and marimo on 8000

SpielerNogard avatar Apr 01 '24 16:04 SpielerNogard

Here is a example:


app = FastAPI(version="0.0.1")


@app.get("/test-endpoint")
async def root():
    return {"message": "Hello World"}

runned with uvicorn server.index:app --reload --port 9000

and the notebook:


__generated_with = "0.3.8"
app = marimo.App()


@app.cell
def __():
   import requests
   resp = requests.get('http://localhost:9000/test-endpoint')
   return requests, resp


@app.cell
def __(resp):
   resp.json()
   return


@app.cell
def __():
   return


if __name__ == "__main__":
   app.run()

Now it works somehow, but the Notebook interacts with the API under enpoint

INFO:     127.0.0.1:61383 - "POST /api/kernel/set_ui_element_value HTTP/1.1" 404 Not Found
INFO:     127.0.0.1:61427 - "POST /api/kernel/set_ui_element_value HTTP/1.1" 404 Not Found

This is a realy weird interaction

SpielerNogard avatar Apr 01 '24 16:04 SpielerNogard

can you include your docker run command? what port are you exposing? what port are you mapping it to?

mscolnick avatar Apr 19 '24 14:04 mscolnick

closing this issue - it seems to be a docker setup issue, but please re-open if you think this is a marimo issue

mscolnick avatar Jun 20 '24 14:06 mscolnick