fastapi-mqtt
fastapi-mqtt copied to clipboard
error Application startup failed. Exiting. when running!
Hi there. I implemented codes example but I get this error when uvicorn runs:
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/starlette/routing.py", line 540, in lifespan
async for item in self.lifespan_context(app):
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/starlette/routing.py", line 481, in default_lifespan
await self.startup()
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/starlette/routing.py", line 516, in startup
await handler()
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/fastapi_mqtt/fastmqtt.py", line 276, in startup
await self.connection()
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/fastapi_mqtt/fastmqtt.py", line 128, in connection
await self.client.connect(self.client._host,self.client._port,self.client._ssl,self.client._keepalive,version)
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/gmqtt/client.py", line 225, in connect
self._connection = await self._create_connection(
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/gmqtt/client.py", line 241, in _create_connection
connection = await MQTTConnection.create_connection(host, port, ssl, clean_session, keepalive)
File "/home/ali/Documents/first_fastapi/venv/lib/python3.9/site-packages/gmqtt/mqtt/connection.py", line 27, in create_connection
transport, protocol = await loop.create_connection(MQTTProtocol, host, port, ssl=ssl)
File "uvloop/loop.pyx", line 2024, in create_connection
File "uvloop/loop.pyx", line 2001, in uvloop.loop.Loop.create_connection
ConnectionRefusedError: [Errno 111] Connection refused
ERROR: Application startup failed. Exiting.
Hi, Can you provide a code example?
I came across the same error today
same here. Looks like with the changes in asyncio, the call to loop doesn't seem to work anymore
how do you guys run applications, could you please provide code examples?
I am experiencing an application startup error as well. Using the code in the example folder and running with:
uvicorn app:app --reload
I have tried specifying different hosts and ports when running and in the MQTTConfig. Any updates on this?
I have the same bug using code from here. I'm using wsl2 with debian 11, python 3.10.3, fastapi 0.75.2 and running it with command uvicorn main:app
Has this issue been resolved? I've noticed it with all example code provided in the documentation.
run using unvicorn and same startup method as @Gipssik
Well I don't how you run the application but I will provide the way in which I run the application and perfectly works
docker run -it -p 1883:1883 eclipse-mosquitto mosquitto -c /mosquitto-no-auth.conf
Then I use the code example from the README.md file.
with uvicorn uvicorn app:app --port 8002 --reload
I run the fastapi app
once I publish the topic /mqtt
I can receive the message from broker to the app.
I am also facing the same issue.
I will try to check locally again, I know that #25 error happens with gunicorn, but with uvicorn but should not be having issues. please confirm your connection, but with paho-mqtt you can check?
With latest versions, the example apps should work out-of-the-box.
Using a fresh clone and install:
git clone https://github.com/sabuhish/fastapi-mqtt.git
cd fastapi-mqtt
poetry install
poetry shell
uvicorn examples.app:app --port 8000
I'm closing this issue, as completed. Please feel free to re-open it if facing this issue again (and provide details about the used environment 🙏)