Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

728
Views
No se pueden obtener datos del cliente en FastAPI websocket | Pitón

Recibo este error en mi registro fastapi:

 INFO: ('172.28.0.1', 35088) - "WebSocket /ws" [accepted] INFO: connection open ERROR: Exception in ASGI application ... await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 58, in __call__ await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 580, in __call__ await route.handle(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 68, in app await func(session) File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 273, in app await dependant.call(**values) File "/code/./app/main.py", line 127, in websocket_endpoint data = await websocket.receive_text() File "/usr/local/lib/python3.9/site-packages/starlette/websockets.py", line 85, in receive_text self._raise_on_disconnect(message) File "/usr/local/lib/python3.9/site-packages/starlette/websockets.py", line 80, in _raise_on_disconnect raise WebSocketDisconnect(message["code"]) starlette.websockets.WebSocketDisconnect: 1000 INFO: connection closed

No puedo encontrar el problema. ¿Por qué mi ruta fastapi no puede obtener los datos del cliente pero el mensaje del servidor al cliente funciona?

Codigo del cliente:

 import asyncio from time import sleep import websockets async def get_work(): async with websockets.connect("ws://localhost:3000/ws", open_timeout=None) as websocket: await websocket.send('Hello from CLient') answer = await websocket.recv() print(answer) while True: asyncio.run(get_work()) sleep(5)

Código del servidor:

 @app.websocket("/ws") async def websocket_endpoint(websocket: WebSocket): await websocket.accept() while True: try: data = await websocket.receive_text() print(data) except RuntimeError: break await websocket.send_text("Hello from Server")

¡Muchas gracias por la ayuda!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!