Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
srcao-bingo opened this issue Sep 16, 2023 · 20 comments
Labels
bug Something isn't working

Comments

@srcao-bingo
Copy link

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
Copy link
Author

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

@snowby666
Copy link
Owner

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

@srcao-bingo
Copy link
Author

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
Copy link
Author

下载_00

@snowby666
Copy link
Owner

snowby666 commented Sep 16, 2023

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)?

@srcao-bingo
Copy link
Author

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
Copy link
Author

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
Copy link

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
Copy link
Author

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

@snowby666 snowby666 added the bug Something isn't working label Dec 1, 2023
@Hecbi
Copy link

Hecbi commented Jan 15, 2024

他的默认代理检测器找不到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)

这个方法对我好用

@srcao-bingo
Copy link
Author

srcao-bingo commented Feb 4, 2024

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

@srcao-bingo
Copy link
Author

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

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

@qiuzhen8484
Copy link

qiuzhen8484 commented May 7, 2024

他的默认代理检测器找不到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
Copy link

http_proxy_port

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

@qiuzhen8484
Copy link

他的默认代理检测器找不到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

@toyosky
Copy link

toyosky commented May 15, 2024

http_proxy_port

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

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

@qiuzhen8484
Copy link

http_proxy_port

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

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

不能

@liang-zijian
Copy link

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

@toyosky
Copy link

toyosky commented May 18, 2024

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

@owlsan49
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants