bluet / proxybroker2

The New (auto rotate) Proxy [Finder | Checker | Server]. HTTP(S) & SOCKS :performing_arts:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When running on Windows 11, the following error occurs. how to fix it?

surgutandrey opened this issue · comments

When running on Windows 11, the following error occurs. how to fix it?

PS D:\GitRepo\PythonTest> & d:/GitRepo/PythonTest/.venv/Scripts/python.exe d:/GitRepo/PythonTest/ProxyBroker2.py
Traceback (most recent call last):
File "d:\GitRepo\PythonTest\ProxyBroker2.py", line 11, in
broker = Broker(proxies)
^^^^^^^^^^^^^^^
File "D:\GitRepo\PythonTest.venv\Lib\site-packages\proxybroker\api.py", line 69, in init
self._resolver = Resolver(loop=self._loop)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\GitRepo\PythonTest.venv\Lib\site-packages\proxybroker\resolver.py", line 48, in init
self._resolver = aiodns.DNSResolver(loop=self.loop)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\GitRepo\PythonTest.venv\Lib\site-packages\aiodns_init
.py", line 55, in init
raise RuntimeError(
RuntimeError: aiodns needs a SelectorEventLoop on Windows. See more: saghul/aiodns#86
PS D:\GitRepo\PythonTest>

my guess is that you would need to use asyncio.new_event_loop() instead of asyncio.get_event_loop().

But instead of guessing, giving a minimally reproducible example would be more beneficial.

I use Windows. I'm using the sample code from the readme:

import asyncio
from proxybroker import Broker

async def show(proxies):
    while True:
        proxy = await proxies.get()
        if proxy is None: break
        print('Found proxy: %s' % proxy)

proxies = asyncio.Queue()
broker = Broker(proxies)
tasks = asyncio.gather(
    broker.find(types=['HTTP',], limit=10),
    show(proxies))

loop = asyncio.get_event_loop()
loop.run_until_complete(tasks)

I get the following error:

PS D:\GitRepo\PythonTest> & d:/GitRepo/PythonTest/.venv/Scripts/python.exe d:/GitRepo/PythonTest/ProxyBroker2.py
Traceback (most recent call last):
  File "d:\GitRepo\PythonTest\ProxyBroker2.py", line 11, in <module>
    broker = Broker(proxies)
             ^^^^^^^^^^^^^^^
  File "D:\GitRepo\PythonTest\.venv\Lib\site-packages\proxybroker\api.py", line 69, in __init__
    self._resolver = Resolver(loop=self._loop)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitRepo\PythonTest\.venv\Lib\site-packages\proxybroker\resolver.py", line 48, in __init__
    self._resolver = aiodns.DNSResolver(loop=self._loop)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitRepo\PythonTest\.venv\Lib\site-packages\aiodns\__init__.py", line 55, in __init__
    raise RuntimeError(
RuntimeError: aiodns needs a SelectorEventLoop on Windows. See more: https://github.com/saghul/aiodns/issues/86
PS D:\GitRepo\PythonTest> 

I studied the link (saghul/aiodns#86), but it is not clear how to fix it! I ask for help in fixing the problem!

Does this problem have a solution?

yes
#147 (comment)

it is the only workaround for now

What exactly should be done? In the provided answer, it is not clear exactly what actions are needed!

Please look at this example

PS D:\GitRepo\PythonTest> & d:/GitRepo/PythonTest/.venv/Scripts/python.exe d:/GitRepo/PythonTest/ProxyBroker2.py
D:\GitRepo\PythonTest.venv\Lib\site-packages\proxybroker\providers.py:77: DeprecationWarning: The object should be created within an async function
async with aiohttp.ClientSession(
D:\GitRepo\PythonTest.venv\Lib\site-packages\aiohttp\connector.py:776: DeprecationWarning: The object should be created within an async function
super().init(
D:\GitRepo\PythonTest.venv\Lib\site-packages\aiohttp\cookiejar.py:84: DeprecationWarning: The object should be created within an async function
super().init(loop=loop)

What python version are you running?

oh i forgot, my pull request haven't been merged yet. PR #147 will fix this.

what specific action should be done? Nothing is clear in this discussion

add the following code after you import asyncio

if sys.platform == 'win32':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())