Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4660

Troubleshooting • FastAPI and Uvicorn bind to Static IP

$
0
0
Hi, I've been playing with FastAPI and uvicorn to use as a webserver. Here's my python example with install notes:

Code:

import uvicornfrom fastapi import FastAPI#from fastapi import FastAPI, HTTPException, Depends, statusfrom fastapi.responses import HTMLResponse#from fastapi import Response#sudo apt install python3-uvicorn#sudo apt install python3-fastapi#sudo apt install python3-sqlalchemyapp = FastAPI()@app.get("/", response_class=HTMLResponse)async def root():content = "HELLO THERE"#with open('pages/index.html', 'r') as file:#content = file.read()return contentif __name__ == "__main__":uvicorn.run(app, port=8080)
Because I'm trying to bind the IP I am getting the following error:
INFO: Application startup complete.
ERROR: [Errno 99] error while attempting to bind on address ('192.168.1.253', 80): cannot assign requested address
INFO: Waiting for application shutdown.
TBH, I've just remembered I hadn't been able to bind the static IP either yet...

I had investigated ufw, was that right, good, bad...?

Code:

sudo apt-get install ufwsudo ufw enablesudo ufw allow sshsudo ufw allow 8080
Enlighten me whilst I go try the static ip... :D

Hi!

Statistics: Posted by skeg_rocks — Tue Oct 08, 2024 4:17 pm — Replies 1 — Views 66



Viewing all articles
Browse latest Browse all 4660

Trending Articles