# How can I use Gradio websocket API

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-can-i-use-gradio-websocket-api%2F44789%3E%5C
**Category:** 🔒 Gradio\
**Created:** [June 28, 2023, 5:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-can-i-use-gradio-websocket-api%2F44789 "2023-06-28T05:47:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RockmanYang](https://avatars.discourse-cdn.com/v4/letter/r/f9ae1b/32.png) [@RockmanYang](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRockmanYang)%5C
**Post date:** [June 28, 2023, 5:47am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-can-i-use-gradio-websocket-api%2F44789%2F1 "2023-06-28T05:47:54Z")

</div>

I make a Android App with JAVA. I can’t use the Python or JS Gradio API.  
Then, I have called Gradio API with REST. It is work ok if process (file) is short time. But It will disconnect if HTTP timeout when processing big file.  
Then, I try to use the websocket API(undocument) to connect the Gradio ,  
I refer the link [https://prog.world/artificial-artist-google-from-text-to-img-world/](https://prog.world/artificial-artist-google-from-text-to-img-world/) .  
It looks work a few days, But it will fail alway after some days.  
I look the error in spaces’s logs. It will occur when the websocket start to connect, before send any message. I wonder why the server block the connecting? Do I lost some operation?  
Then , I have use different Android websocket library (AndroidAsync or autobahn-java]) to check it , It looks like the server issue.  
I want konw anyone meeting the issue?

-----------------------------------------------logs---------------------------------------------------------------------  
ERROR: Exception in ASGI application  
Traceback (most recent call last):  
File “/home/user/.local/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets\_impl.py”, line 254, in run\_asgi  
result = await self.app(self.scope, self.asgi\_receive, self.asgi\_send)  
File “/home/user/.local/lib/python3.10/site-packages/uvicorn/middleware/proxy\_headers.py”, line 78, in **call**  
return await self.app(scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/fastapi/applications.py”, line 282, in **call**  
await super(). **call** (scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/applications.py”, line 122, in **call**  
await self.middleware\_stack(scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/middleware/errors.py”, line 149, in **call**  
await self.app(scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/middleware/cors.py”, line 75, in **call**  
await self.app(scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/middleware/exceptions.py”, line 79, in **call**  
raise exc  
File “/home/user/.local/lib/python3.10/site-packages/starlette/middleware/exceptions.py”, line 68, in **call**  
await self.app(scope, receive, sender)  
File “/home/user/.local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py”, line 20, in **call**  
raise e  
File “/home/user/.local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py”, line 17, in **call**  
await self.app(scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/routing.py”, line 718, in **call**  
await route.handle(scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/routing.py”, line 341, in handle  
await self.app(scope, receive, send)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/routing.py”, line 82, in app  
await func(session)  
File “/home/user/.local/lib/python3.10/site-packages/fastapi/routing.py”, line 292, in app  
await dependant.call(\*\*values)  
File “/home/user/.local/lib/python3.10/site-packages/gradio/routes.py”, line 421, in join\_queue  
session\_info = await websocket.receive\_json()  
File “/home/user/.local/lib/python3.10/site-packages/starlette/websockets.py”, line 133, in receive\_json  
self.\_raise\_on\_disconnect(message)  
File “/home/user/.local/lib/python3.10/site-packages/starlette/websockets.py”, line 105, in \_raise\_on\_disconnect  
raise WebSocketDisconnect(message[“code”])  
starlette.websockets.WebSocketDisconnect: 1006
