codeinterpreter-api icon indicating copy to clipboard operation
codeinterpreter-api copied to clipboard

Server rejected WebSocket connection: HTTP 404

Open N4RLY opened this issue 1 year ago • 2 comments

I took code from the first example in readme file:

from codeinterpreterapi import CodeInterpreterSession, settings

# create a session and close it automatically
with CodeInterpreterSession() as session:
    # generate a response based on user input
    response = session.generate_response(
        "Plot the bitcoin chart of year 2023"
    )
    # output the response
    response.show()

And got this traceback:

Using Chat OpenAI
Starting kernel...
Waiting for kernel to start...
Attempt 1: WebSocket connection failed. Error: timed out during handshake

---------------------------------------------------------------------------

InvalidStatus                             Traceback (most recent call last)

[<ipython-input-5-7a437c822d36>](https://localhost:8080/#) in <cell line: 4>()
      2 
      3 # create a session and close it automatically
----> 4 with CodeInterpreterSession() as session:
      5     # generate a response based on user input
      6     response = session.generate_response(

7 frames

[/usr/local/lib/python3.10/dist-packages/codeinterpreterapi/session.py](https://localhost:8080/#) in __enter__(self)
    485 
    486     def __enter__(self) -> "CodeInterpreterSession":
--> 487         self.start()
    488         return self
    489 

[/usr/local/lib/python3.10/dist-packages/codeinterpreterapi/session.py](https://localhost:8080/#) in start(self)
     88 
     89     def start(self) -> SessionStatus:
---> 90         status = SessionStatus.from_codebox_status(self.codebox.start())
     91         self.agent_executor = self._agent_executor()
     92         self.codebox.run(

[/usr/local/lib/python3.10/dist-packages/codeboxapi/box/localbox.py](https://localhost:8080/#) in start(self)
    105                 print("Waiting for kernel to start...")
    106             time.sleep(1)
--> 107         self._connect()
    108         return CodeBoxStatus(status="started")
    109 

[/usr/local/lib/python3.10/dist-packages/codeboxapi/box/localbox.py](https://localhost:8080/#) in _connect(self)
    131         for attempt in range(5):
    132             try:
--> 133                 self.ws = ws_connect_sync(
    134                     f"{self.ws_url}/kernels/{self.kernel_id}/channels",
    135                     open_timeout=60,

[/usr/local/lib/python3.10/dist-packages/websockets/sync/client.py](https://localhost:8080/#) in connect(uri, sock, ssl_context, server_hostname, unix, path, origin, extensions, subprotocols, additional_headers, user_agent_header, compression, open_timeout, close_timeout, max_size, logger, create_connection)
    287         )
    288         # On failure, handshake() closes the socket and raises an exception.
--> 289         connection.handshake(
    290             additional_headers,
    291             user_agent_header,

[/usr/local/lib/python3.10/dist-packages/websockets/sync/client.py](https://localhost:8080/#) in handshake(self, additional_headers, user_agent_header, timeout)
     96 
     97         if self.protocol.handshake_exc is not None:
---> 98             raise self.protocol.handshake_exc
     99 
    100     def process_event(self, event: Event) -> None:

[/usr/local/lib/python3.10/dist-packages/websockets/client.py](https://localhost:8080/#) in parse(self)
    336 
    337             try:
--> 338                 self.process_response(response)
    339             except InvalidHandshake as exc:
    340                 response._exception = exc

[/usr/local/lib/python3.10/dist-packages/websockets/client.py](https://localhost:8080/#) in process_response(self, response)
    150 
    151         if response.status_code != 101:
--> 152             raise InvalidStatus(response)
    153 
    154         headers = response.headers

InvalidStatus: server rejected WebSocket connection: HTTP 404

I don't know why, but I can't connect to the server. I found that kernel can't start. Anyone knows how to solve this problem?

Any help is appreciated :)

N4RLY avatar Mar 03 '24 12:03 N4RLY

I am having same error

websockets.exceptions.InvalidStatusCode

websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404

Someone should please help

@shroominic please help

okoliechykwuka avatar Mar 11 '24 11:03 okoliechykwuka

I resolved this by installing latest versions of the following:

jupyter-kernel-gateway==3.0.1    
jupyter-client==8.6.1   
notebook==7.1.2

jonah-ramponi avatar Mar 20 '24 14:03 jonah-ramponi