fastapi-socketio icon indicating copy to clipboard operation
fastapi-socketio copied to clipboard

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

Open ermal-abiti opened this issue 2 years ago • 2 comments

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())

ermal-abiti avatar Jul 28 '22 07:07 ermal-abiti

pip install python-socketio[asyncio_client]

baozaodetudou avatar Aug 01 '22 08:08 baozaodetudou

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())

Adam-D-Lewis avatar Aug 05 '22 23:08 Adam-D-Lewis