snowby666 / poe-api-wrapper

👾 A Python API wrapper for Poe.com. With this, you will have free access to GPT-4, Claude, Llama, Gemini, Mistral and more! 🚀
https://pypi.org/project/poe-api-wrapper/
GNU General Public License v3.0
677 stars 81 forks source link

Proxy connection failed. poe_api_wrapper.api:select_proxy:202 - Connection failed with {'http': '...'}. #124

Closed PMajesty closed 1 week ago

PMajesty commented 3 months ago

I set up my own http proxy that works upon curling quora:

1

However, when I use it with this package:

2

It can't connect:

3

The stuff I hid with the blue color is the same proxy ip + port. Am I doing something wrong or is this a bug of some sorts?

snowby666 commented 3 months ago

image I think its a bug. I tested with a proxy and it worked normally.

srcao-bingo commented 3 months ago

这么设置好像行不通,需要在 api.py 中进一步修改吗? image

2024-03-20 10:20:06.357 | WARNING | poe_api_wrapper.api:on_ws_close:296 - Connection to remote host was lost. Reconnecting... 2024-03-20 10:20:15.887 | INFO | poe_api_wrapper.api:select_proxy:126 - Connection failed with {'https': 'socks5://127.0.0.1:7890', 'http': 'socks5://127.0.0.1:7890'}. Trying 1/1 ... 2024-03-20 10:20:30.446 | WARNING | poe_api_wrapper.api:on_ws_close:296 - Connection to remote host was lost. Reconnecting... 2024-03-20 10:20:54.176 | WARNING | poe_api_wrapper.api:on_ws_close:296 - Connection to remote host was lost. Reconnecting... Traceback (most recent call last): File "E:\OneDrive\2-code\Source\utils\poe-api-wrapper-V2\poe_api_wrapper_v2_main.py", line 40, in for chunk in client.send_message(bot, message): File "C:\Users\cao.conda\envs\poe-api-wrapper\lib\site-packages\poe_api_wrapper\api.py", line 691, in send_message self.connect_ws() File "C:\Users\cao.conda\envs\poe-api-wrapper\lib\site-packages\poe_api_wrapper\api.py", line 280, in connect_ws raise RuntimeError("Timed out waiting for websocket to connect.") RuntimeError: Timed out waiting for websocket to connect.

PMajesty commented 3 months ago

Yeah. I managed to fix the proxy problem by modifying the code a bit, but now the connection times out. I managed to work around it like this, but it is a clunky solution and it's far from perfect:

async def send_bot_message(bot_name, chat_id, text):
    global client  # Declare client as global within this function
    while True:
        try:
            response_chunks = []
            for chunk in client.send_message(bot_name, text, chatId=chat_id):
                response_chunks.append(chunk["response"])
            return ''.join(response_chunks)
        except requests.exceptions.ConnectionError:
            client = PoeApi(cookie=tokens, proxy=proxy_url)

Please take a look at this problem

snowby666 commented 1 week ago

This is be fixed in v.1.5.4