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

Using third-party proxy Clash, ballyregan called by PoeApi cannot read proxy information from the system

Open srcao-bingo opened this issue 1 year ago • 20 comments

When I run the sample code below, I get the following error:

`from poe_api_wrapper import PoeApi

token = "************"

bot = "a2" message = "What is reverse engineering?"

client = PoeApi(token, proxy=True)

for chunk in client.send_message(bot, message): print(chunk["response"], end="", flush=True)`

client = PoeApi(token, proxy=True)

File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\poe_api_wrapper\api.py", line 110, in init proxies = fetch_proxy() File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\poe_api_wrapper\proxies.py", line 19, in fetch_proxy proxies = fetcher.get( File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\ballyregan\fetcher.py", line 134, in get proxies = self._gather( File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\ballyregan\fetcher.py", line 104, in _gather raise NoProxiesFound ballyregan.core.exceptions.NoProxiesFound: Could not find any proxies

srcao-bingo avatar Sep 16 '23 08:09 srcao-bingo

I installed poe_api_wrapper[proxy]. My operating system is Win11, and the Python version is 3.9.12

srcao-bingo avatar Sep 16 '23 08:09 srcao-bingo

Well there was no proxy at that moment. My unit test still works

snowby666 avatar Sep 16 '23 09:09 snowby666

Did you enable Clash or other proxy software when testing? I keep Clash on when running the sample code. If I turn off Clash, I can't access Poe.com.

srcao-bingo avatar Sep 16 '23 09:09 srcao-bingo

下载_00

srcao-bingo avatar Sep 16 '23 09:09 srcao-bingo

i cant help beyond that then since it depends on ballyregan for auto-proxy method. Can you use the lib with just client = PoeApi(token)?

snowby666 avatar Sep 16 '23 09:09 snowby666

I still can't use it.

client = PoeApi(token) File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\poe_api_wrapper\api.py", line 124, in init 'Quora-Formkey': self.get_formkey, File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\poe_api_wrapper\api.py", line 144, in get_formkey response = self.client.get(self.BASE_URL, headers=self.HEADERS, follow_redirects=True) File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_client.py", line 1041, in get return self.request( File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_client.py", line 814, in request return self.send(request, auth=auth, follow_redirects=follow_redirects) File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_client.py", line 901, in send response = self._send_handling_auth( File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_client.py", line 929, in _send_handling_auth response = self._send_handling_redirects( File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_client.py", line 966, in _send_handling_redirects response = self._send_single_request(request) File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_client.py", line 1002, in _send_single_request response = transport.handle_request(request) File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_transports\default.py", line 218, in handle_request resp = self._pool.handle_request(req) File "D:\software\anaconda\lib\contextlib.py", line 137, in exit self.gen.throw(typ, value, traceback) File "C:\Users\cao\AppData\Roaming\Python\Python39\site-packages\httpx_transports\default.py", line 77, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: EOF occurred in violation of protocol (_ssl.c:1129)

srcao-bingo avatar Sep 16 '23 10:09 srcao-bingo

I lowered the version of urllib3 to 1.25.11 and solved the above problem. It shows that the connection is established but another problem occurs. Have you ever encountered this situation? 2023-09-16_19-27-36

srcao-bingo avatar Sep 16 '23 11:09 srcao-bingo

I lowered the version of urllib3 to 1.25.11 and solved the above problem. It shows that the connection is established but another problem occurs. Have you ever encountered this situation? 2023-09-16_19-27-36

请问你的问题解决了吗

llllly26 avatar Sep 24 '23 03:09 llllly26

I lowered the version of urllib3 to 1.25.11 and solved the above problem. It shows that the connection is established but another problem occurs. Have you ever encountered this situation? 2023-09-16_19-27-36

请问你的问题解决了吗

今天重新装了一遍,还是同样的问题,换换别的库吧,别在一棵树上吊死。 image

srcao-bingo avatar Sep 28 '23 01:09 srcao-bingo

他的默认代理检测器找不到clash代理,需要修改他的代码,分为两部分:

  1. http代理:修改api.py的__init__ 如下:
def __init__(self, cookie: str, proxy: bool=False):
        self.cookie = cookie
        self.formkey = None
        if proxy == True and PROXY == True:
            # proxies = fetch_proxy()
            # for p in range(len(proxies)):
            try:
                self.proxy = {
                    "http://": "socks5://127.0.0.1:7890",
                    "https://": "socks5://127.0.0.1:7890",
                }
                self.client = Client(headers=self.HEADERS, timeout=180, proxies=self.proxy)
                # logger.info(f"Connection established with {proxies[p]}")
                logger.info("代理连接成功")
                # break
            except:
                # logger.info(f"Connection failed with {proxies[p]}. Trying {p+1}/{len(proxies)} ...")
                logger.error("代理错误")
                sleep(1)
        else:
            self.proxy = None
            self.client = Client(headers=self.HEADERS, timeout=180)
        self.client.cookies.update({'m-b': self.cookie})
        
        self.get_channel_settings()
        
        logger.info("Connection established with poe.com")
        
        self.ws_connecting = False
        self.ws_connected = False
        self.ws_error = False
        self.active_messages = {}
        self.message_queues = {}
        self.current_thread = {}
        self.retry_attempts = 3
        self.message_generating = True
        self.ws_refresh = 3
        self.groups = {}
        
        self.connect_ws()
  1. websocket代理:修改api.py的ws_run_thread函数如下:
    def ws_run_thread(self):
        if not self.ws.sock:
            kwargs = {"sslopt": {"cert_reqs": ssl.CERT_NONE}, "http_proxy_host":"127.0.0.1", "http_proxy_port": 10808, "proxy_type": "socks5"}
            self.ws.run_forever(**kwargs)

这个方法对我好用

Hecbi avatar Jan 15 '24 07:01 Hecbi

@Hecbi 首先非常感谢您的分享,我今晚尝试后也能正确识别代理,不过仍存在下面这个问题 image 我分别使用了quora.com 和 poe.com 最新的 token ,也更新了 poe-api-wrapper ,我不太清楚是什么原因导致该问题。如果您曾遇到过相似的问题,方便分享一下您是如何解决的吗?

srcao-bingo avatar Feb 04 '24 15:02 srcao-bingo

@Hecbi 首先非常感谢您的分享,我今晚尝试后也能正确识别代理,不过仍存在下面这个问题 image 我分别使用了quora.com 和 poe.com 最新的 token ,也更新了 poe-api-wrapper ,我不太清楚是什么原因导致该问题。如果您曾遇到过相似的问题,方便分享一下您是如何解决的吗?

找到原因了,def ws_run_thread(self) 中的 "http_proxy_port"这个端口号需要修改成自己的端口。 终于可以愉快的玩耍了,再次感谢!

srcao-bingo avatar Feb 05 '24 15:02 srcao-bingo

他的默认代理检测器找不到clash代理,需要修改他的代码,分为两部分:

  1. http代理:修改api.py的__init__ 如下:
def __init__(self, cookie: str, proxy: bool=False):
        self.cookie = cookie
        self.formkey = None
        if proxy == True and PROXY == True:
            # proxies = fetch_proxy()
            # for p in range(len(proxies)):
            try:
                self.proxy = {
                    "http://": "socks5://127.0.0.1:7890",
                    "https://": "socks5://127.0.0.1:7890",
                }
                self.client = Client(headers=self.HEADERS, timeout=180, proxies=self.proxy)
                # logger.info(f"Connection established with {proxies[p]}")
                logger.info("代理连接成功")
                # break
            except:
                # logger.info(f"Connection failed with {proxies[p]}. Trying {p+1}/{len(proxies)} ...")
                logger.error("代理错误")
                sleep(1)
        else:
            self.proxy = None
            self.client = Client(headers=self.HEADERS, timeout=180)
        self.client.cookies.update({'m-b': self.cookie})
        
        self.get_channel_settings()
        
        logger.info("Connection established with poe.com")
        
        self.ws_connecting = False
        self.ws_connected = False
        self.ws_error = False
        self.active_messages = {}
        self.message_queues = {}
        self.current_thread = {}
        self.retry_attempts = 3
        self.message_generating = True
        self.ws_refresh = 3
        self.groups = {}
        
        self.connect_ws()
  1. websocket代理:修改api.py的ws_run_thread函数如下:
    def ws_run_thread(self):
        if not self.ws.sock:
            kwargs = {"sslopt": {"cert_reqs": ssl.CERT_NONE}, "http_proxy_host":"127.0.0.1", "http_proxy_port": 10808, "proxy_type": "socks5"}
            self.ws.run_forever(**kwargs)

这个方法对我好用

请问我使用了这个代码连接上代理了但还是在response_json = self.client.get(f'{self.BASE_URL}/poe_api/settings', headers=self.HEADERS, timeout=30).json() 这一句出现错误EOF occurred in violation of protocol (_ssl.c:1129) ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1129) 安装的是poe-api-wrapper[proxy]

image image

qiuzhen8484 avatar May 07 '24 03:05 qiuzhen8484

http_proxy_port

请问你现在还能正常使用吗?

qiuzhen8484 avatar May 07 '24 03:05 qiuzhen8484

他的默认代理检测器找不到clash代理,需要修改他的代码,分为两部分:

  1. http代理:修改api.py的__init__ 如下:
def __init__(self, cookie: str, proxy: bool=False):
        self.cookie = cookie
        self.formkey = None
        if proxy == True and PROXY == True:
            # proxies = fetch_proxy()
            # for p in range(len(proxies)):
            try:
                self.proxy = {
                    "http://": "socks5://127.0.0.1:7890",
                    "https://": "socks5://127.0.0.1:7890",
                }
                self.client = Client(headers=self.HEADERS, timeout=180, proxies=self.proxy)
                # logger.info(f"Connection established with {proxies[p]}")
                logger.info("代理连接成功")
                # break
            except:
                # logger.info(f"Connection failed with {proxies[p]}. Trying {p+1}/{len(proxies)} ...")
                logger.error("代理错误")
                sleep(1)
        else:
            self.proxy = None
            self.client = Client(headers=self.HEADERS, timeout=180)
        self.client.cookies.update({'m-b': self.cookie})
        
        self.get_channel_settings()
        
        logger.info("Connection established with poe.com")
        
        self.ws_connecting = False
        self.ws_connected = False
        self.ws_error = False
        self.active_messages = {}
        self.message_queues = {}
        self.current_thread = {}
        self.retry_attempts = 3
        self.message_generating = True
        self.ws_refresh = 3
        self.groups = {}
        
        self.connect_ws()
  1. websocket代理:修改api.py的ws_run_thread函数如下:
    def ws_run_thread(self):
        if not self.ws.sock:
            kwargs = {"sslopt": {"cert_reqs": ssl.CERT_NONE}, "http_proxy_host":"127.0.0.1", "http_proxy_port": 10808, "proxy_type": "socks5"}
            self.ws.run_forever(**kwargs)

这个方法对我好用

请问我使用了这个代码把socket5(直接连不上代理)改为http后,连接上代理了但还是在response_json = self.client.get(f'{self.BASE_URL}/poe_api/settings', headers=self.HEADERS, timeout=30).json() 这一句出现错误EOF occurred in violation of protocol (_ssl.c:1129) ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1129) 安装的是poe-api-wrapper[proxy]

image image

qiuzhen8484 avatar May 08 '24 09:05 qiuzhen8484

http_proxy_port

请问你现在还能正常使用吗?

请问你最后能用了吗?跪谢

toyosky avatar May 15 '24 07:05 toyosky

http_proxy_port

请问你现在还能正常使用吗?

请问你最后能用了吗?跪谢

不能

qiuzhen8484 avatar May 15 '24 07:05 qiuzhen8484

I find a new way to solve this problem😄.It may not work for everyone.

  • Windows 11
  • Clash v0.20.39
  • python 3.10
  • poe-api-wrapper (not proxy version!)
from poe_api_wrapper import PoeExample
import os
os.environ["http_proxy"] = "http://127.0.0.1:7890"
os.environ["https_proxy"] = "http://127.0.0.1:7890"
tokens = {
    'b': 'xxx', 
    'lat': 'xxx'
}
PoeExample(cookie=tokens).chat_with_bot()

And the most important thing is to set Clash like this(turn off system proxy, switch to Global mode and select an available node): image

liang-zijian avatar May 18 '24 03:05 liang-zijian

I find a new way to solve this problem😄.It may not work for everyone.

  • Windows 11
  • Clash v0.20.39
  • python 3.10
  • poe-api-wrapper (not proxy version!)
from poe_api_wrapper import PoeExample
import os
os.environ["http_proxy"] = "http://127.0.0.1:7890"
os.environ["https_proxy"] = "http://127.0.0.1:7890"
tokens = {
    'b': 'xxx', 
    'lat': 'xxx'
}
PoeExample(cookie=tokens).chat_with_bot()

And the most important thing is to set Clash like this(turn off system proxy, switch to Global mode and select an available node): image

Thank you very much. I make it. love you

toyosky avatar May 18 '24 07:05 toyosky

I find a new way to solve this problem😄.It may not work for everyone.

  • Windows 11
  • Clash v0.20.39
  • python 3.10
  • poe-api-wrapper (not proxy version!)
from poe_api_wrapper import PoeExample
import os
os.environ["http_proxy"] = "http://127.0.0.1:7890"
os.environ["https_proxy"] = "http://127.0.0.1:7890"
tokens = {
    'b': 'xxx', 
    'lat': 'xxx'
}
PoeExample(cookie=tokens).chat_with_bot()

And the most important thing is to set Clash like this(turn off system proxy, switch to Global mode and select an available node): image

It works for me

owlsan49 avatar May 18 '24 10:05 owlsan49

This is be fixed in v.1.5.4

snowby666 avatar Jun 21 '24 07:06 snowby666