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

Unable to send message after a period of time

Open Seikaijyu opened this issue 1 year ago • 6 comments

The parameters for sending a message are as follows. It seems that the connection will be disconnected after a period of time, and then it will never be connected again

for chunk in self.client.send_message(self.useAi, message,timeout=120):
        pass

Additionally, I used a proxy The command line error is as follows: image Although it appears that the request was successful, it did not actually occur. My account has not received any requests

It seems that the connection was not successful. In previous versions, my usage was normal, and I believe it was caused by the deletion of the following code: Latest version

  def send_message(self, chatbot, message, with_chat_break=False, timeout=20):
    # if there is another active message, wait until it has finished sending
    timer = 0
    while None in self.active_messages.values():
      time.sleep(0.01)
      timer += 0.01
      if timer > timeout:
        raise RuntimeError("Timed out waiting for other messages to send.")

    # None indicates that a message is still in progress
    self.active_messages["pending"] = None

    # reconnect websocket
    while self.ws_error:
      time.sleep(0.01)

    self.connect_ws()
    ..............
    ..............

No version with this issue

  def send_message(self, chatbot, message, with_chat_break=False, timeout=20):
    # if there is another active message, wait until it has finished sending
    timer = 0
    while None in self.active_messages.values():
      time.sleep(0.01)
      timer += 0.01
      if timer > timeout:
        raise RuntimeError("Timed out waiting for other messages to send.")

    # None indicates that a message is still in progress
    self.active_messages["pending"] = None

    logger.info(f"Sending message to {chatbot}: {message}")

    # reconnect websocket
    if not self.ws_connected:
      self.disconnect_ws()
      self.setup_connection()
      self.connect_ws()
    .................
    .................

As can be seen, the latest version has removed the reconnected function self.disconnect_ws() and self.setup_connection() This is just my guess, does anyone know the reason?

Seikaijyu avatar Jun 08 '23 14:06 Seikaijyu

Idk bro. Im no big python/poe api expert

haruki-py avatar Jun 08 '23 14:06 haruki-py

I have encountered the same problem lately, with frequent timeouts.

wingeva1986 avatar Jun 08 '23 16:06 wingeva1986

I'm planning on completely rewriting the websocket handler for this library, which should fix this.

ading2210 avatar Jun 09 '23 01:06 ading2210

Okay

On 09-Jun-2023 7:26 AM, "ading2210" @.***> wrote:

I'm planning on completely rewriting the websocket handler for this library, which should fix this.

— Reply to this email directly, view it on GitHub https://github.com/ading2210/poe-api/issues/106#issuecomment-1583818840, or unsubscribe https://github.com/notifications/unsubscribe-auth/BACG5QTJR5CWHVUM6IURMCDXKJ7FNANCNFSM6AAAAAAY7LL7EE . You are receiving this because you commented.Message ID: @.***>

haruki-py avatar Jun 09 '23 01:06 haruki-py

I have encountered the same problem lately, with frequent timeouts.

Re add the deleted function, but do not add an 'if' statement. This will cause every request you make to reconnect to the websocket, which can temporarily alleviate this problem. However, after a certain time or number of times, the above problem may still occur, but it is much better than not using this solution, so this is only a temporary solution

Seikaijyu avatar Jun 09 '23 02:06 Seikaijyu

same problem

fkx816 avatar Jun 11 '23 05:06 fkx816