proxybroker2 icon indicating copy to clipboard operation
proxybroker2 copied to clipboard

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

Open surgutandrey opened this issue 1 year ago • 12 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: https://github.com/saghul/aiodns/issues/86 PS D:\GitRepo\PythonTest>

surgutandrey avatar Jan 16 '24 15:01 surgutandrey

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.

ziloka avatar Jan 17 '24 22:01 ziloka

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 (https://github.com/saghul/aiodns/issues/86), but it is not clear how to fix it! I ask for help in fixing the problem!

surgutandrey avatar Jan 18 '24 03:01 surgutandrey

Does this problem have a solution?

surgutandrey avatar Feb 02 '24 10:02 surgutandrey

yes https://github.com/bluet/proxybroker2/pull/147#issuecomment-1899611216

it is the only workaround for now

ziloka avatar Feb 02 '24 11:02 ziloka

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

surgutandrey avatar Feb 02 '24 11:02 surgutandrey

Please look at this example

ziloka avatar Feb 02 '24 13:02 ziloka

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)

surgutandrey avatar Feb 02 '24 14:02 surgutandrey

What python version are you running?

ziloka avatar Feb 04 '24 15:02 ziloka

3.12

surgutandrey avatar Feb 04 '24 15:02 surgutandrey

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

ziloka avatar Feb 06 '24 03:02 ziloka

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

surgutandrey avatar Feb 06 '24 10:02 surgutandrey

add the following code after you import asyncio

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

ziloka avatar Feb 12 '24 13:02 ziloka