PyCharacterAI icon indicating copy to clipboard operation
PyCharacterAI copied to clipboard

TypeError: unsupported operand type(s) for 'in': 'int' and 'EnumType' in curl_cffi WebSocket

Open Zectxr opened this issue 7 months ago • 1 comments

When running an async script using the PyCharacterAI library (which depends on curl_cffi), I encountered a TypeError caused by an invalid enum membership check in the websockets.py file.

This error happen when I take a long time before responding to the bot. For example, after sending a message to a character and waiting a few minutes before replying, the following error is triggered:

TypeError: unsupported operand type(s) for 'in': 'int' and 'EnumType'
  File "websockets.py", line 142, in _unpack_close_frame
    if code < 3000 and (code not in WsCloseCode or code == 1005):```
It seems like the WebSocket connection times out or closes due to inactivity, and the code is not correctly handling the WebSocket close frame.

Name: curl_cffi Version: 0.11.1 OS: Windows 11

Zectxr avatar May 24 '25 16:05 Zectxr

This happens sometimes, curl-cffi is not a perfect library, and c.ai does not always behave consistently. You must handle all errors yourself and repeat method calls again manually. This library does not provide a mechanism for repeating requests automatically, as this would cause unwanted behavior in some cases

Xtr4F avatar May 25 '25 08:05 Xtr4F

This happens sometimes, curl-cffi is not a perfect library, and c.ai does not always behave consistently. You must handle all errors yourself and repeat method calls again manually. This library does not provide a mechanism for repeating requests automatically, as this would cause unwanted behavior in some cases

Thanks fo the response I appreciate it. I've resolved it by upgrading my curl-cffi.

Zectxr avatar May 26 '25 03:05 Zectxr