novnc / websockify

Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.
GNU Lesser General Public License v3.0
3.95k stars 780 forks source link

TypeError: 'str' object cannot be interpreted as an integer #555

Closed shobeiry closed 1 year ago

shobeiry commented 1 year ago

i use websockify in python with FastAPI. i write this code:

@app.websocket("/vnc/{id}/")
async def vnc(websocket: WebSocket, _id: str = Path(..., alias="id", title="Container id is required.")):
    container = docker.containers.get(_id)
    net = container.attrs['NetworkSettings']['Networks']
    net = net[list(net.keys())[0]]
    proxy = WebSocketProxy(websocket, net['IPAddress'], 5901)
    await proxy.start_server()

But I get this error:

Traceback (most recent call last):
  File "...\FastApi\venv\lib\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 "...\FastApi\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\fastapi\applications.py", line 284, in __call__
    await super().__call__(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\starlette\middleware\errors.py", line 149, in __call__
    await self.app(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\starlette\middleware\cors.py", line 75, in __call__
    await self.app(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "...\FastApi\venv\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "...\FastApi\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 20, in __call__
    raise e
  File "...\FastApi\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\starlette\routing.py", line 341, in handle
    await self.app(scope, receive, send)
  File "...\FastApi\venv\lib\site-packages\starlette\routing.py", line 82, in app
    await func(session)
  File "...\FastApi\venv\lib\site-packages\fastapi\routing.py", line 292, in app
    await dependant.call(**values)
  File "...\FastApi\main.py", line 111, in vnc
    await proxy.start_server()
  File "...\FastApi\venv\lib\site-packages\websockify\websockifyserver.py", line 702, in start_server
    lsock = socket.fromfd(self.listen_fd, socket.AF_INET, socket.SOCK_STREAM)
  File "C:\Users\....\AppData\Local\Programs\Python\Python310\lib\socket.py", line 545, in fromfd
    nfd = dup(fd)
TypeError: 'str' object cannot be interpreted as an integer

What is the problem?