pyropy / fastapi-socketio

Easily integrate socket.io with your FastAPI app 🚀
Apache License 2.0
328 stars 31 forks source link

provide an example script to connect by a python socketio.Client instance or from javascript #31

Open ermal-abiti opened 2 years ago

ermal-abiti commented 2 years ago

I have an issue connecting to the fastapi-socketio server by a python script. I am running this code:

import socketio

sio = socketio.Client()
sio.connect('http://0.0.0.0:8000')

I also tried with asyncio and i get another error:

import socketio
import asyncio

sio = socketio.AsyncClient()

async def main():
    await sio.connect('http://0.0.0.0:8000')

asyncio.run(main())
baozaodetudou commented 2 years ago
pip install python-socketio[asyncio_client]
Adam-D-Lewis commented 2 years ago

This worked for me.

import asyncio

sio = socketio.AsyncClient()

async def main():
    await sio.connect('ws://localhost:8000', socketio_path='/ws/socket.io')

asyncio.run(main())