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

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

Open
surgutandrey opened this issue Jan 16, 2024 · 12 comments
Open

Comments

@surgutandrey
Copy link

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: aio-libs/aiodns#86
PS D:\GitRepo\PythonTest>

@ziloka
Copy link

ziloka commented Jan 17, 2024

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.

@surgutandrey
Copy link
Author

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 (aio-libs/aiodns#86), but it is not clear how to fix it! I ask for help in fixing the problem!

@surgutandrey
Copy link
Author

Does this problem have a solution?

@ziloka
Copy link

ziloka commented Feb 2, 2024

yes
#147 (comment)

it is the only workaround for now

@surgutandrey
Copy link
Author

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

@ziloka
Copy link

ziloka commented Feb 2, 2024

Please look at this example

@surgutandrey
Copy link
Author

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)

@ziloka
Copy link

ziloka commented Feb 4, 2024

What python version are you running?

@surgutandrey
Copy link
Author

3.12

@ziloka
Copy link

ziloka commented Feb 6, 2024

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

@surgutandrey
Copy link
Author

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

@ziloka
Copy link

ziloka commented Feb 12, 2024

add the following code after you import asyncio

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants