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

Issue on running the README quickstart script with python 3.8 interpreter #109

Open
boxxello opened this issue Oct 13, 2022 · 9 comments
Open

Comments

@boxxello
Copy link

boxxello commented Oct 13, 2022

I tried the quickstart snippet on 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', 'HTTPS'], limit=10),
    show(proxies))

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

Which gave me this Traceback:
Traceback (most recent call last):
File "C:\Users\boxxo\PycharmProjects\pythonProject12\main.py", line 13, in
broker = Broker(proxies)
File "C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\proxybroker\api.py", line 67, in init
self._loop = loop or asyncio.get_running_loop()
RuntimeError: no running event loop

To Reproduce
Steps to reproduce the behavior:

  1. New environment with conda which automatically adds to the env these packages:

ca-certificates | 2022.07.19 |  
certifi | 2022.9.24 |  
openssl | 1.1.1q |  
pip | 22.2.2 |  
python | 3.8.13 |  
setuptools | 63.4.1 |  
sqlite | 3.39.3 |  
vc | 14.2 |  
vs2015_runtime | 14.27.29016 |  
wheel | 0.37.1 |  
wincertstore | 0.2 |  

  1. pip install -U git+https://github.com/bluet/proxybroker2.git .

  2. run the snippet as described in the readme and stated above .

Expected behavior
Showing proxies in the console.

Desktop (please complete the following information):

  • OS: Windows
  • Browser Not required
  • Version 11

Additional context
I also tried the below by creating a new loop and assigning it to the Broker constructor.

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()
loop=asyncio.new_event_loop()

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

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

Which gave me this traceback:

C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\proxybroker\resolver.py:105: DeprecationWarning: The object should be created within an async function
async with aiohttp.ClientSession(
C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\aiohttp\connector.py:767: DeprecationWarning: The object should be created within an async function
super().init(
C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\aiohttp\cookiejar.py:67: DeprecationWarning: The object should be created within an async function
super().init(loop=loop)
Traceback (most recent call last):
File "C:\Users\boxxo\PycharmProjects\pythonProject12\main.py", line 19, in
loop.run_until_complete(tasks)
File "C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\proxybroker\api.py", line 176, in find
ip = await self._resolver.get_real_ext_ip()
File "C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\proxybroker\resolver.py", line 105, in get_real_ext_ip
async with aiohttp.ClientSession(
File "C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\aiohttp\client.py", line 1141, in aenter
self._resp = await self._coro
File "C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\aiohttp\client.py", line 467, in _request
with timer:
File "C:\Users\boxxo\anaconda3\envs\pythonProject12\lib\site-packages\aiohttp\helpers.py", line 700, in enter
raise RuntimeError(
RuntimeError: Timeout context manager should be used inside a task

I've read that it doesn't support python version 3.10 here : here but I think it should be supporting 3.9/3.8 ? Read it from this commit .

Also I've tried running the same script on a FastAPI instance and it works just fine on 3.8 (not tested yet in 3.9, if needed I can update you on this).

@bluet
Copy link
Owner

bluet commented Nov 4, 2022

@afunTW @vincentinttsh @hms5232 @ziloka able to help on this? 😅

@hms5232
Copy link

hms5232 commented Nov 4, 2022

@afunTW @vincentinttsh @hms5232 @ziloka able to help on this? 😅

This happened in Python 3.9 too.

Traceback (most recent call last):
  File "E:\code\pb109\main.py", line 11, in <module>
    broker = Broker(proxies)
  File "C:\Users\hms5232\AppData\Local\pypoetry\Cache\virtualenvs\pb109-DO4mlOl7-py3.9\lib\site-packages\proxybroker\api.py", line 67, in __init__
    self._loop = loop or asyncio.get_running_loop()
RuntimeError: no running event loop

I use poetry run a virtual env and here is pyproject.toml:

[tool.poetry]
name = "pb109"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.8.3"
wincertstore = "0.2"
certifi = "2022.9.24"
proxybroker = {git = "https://github.com/bluet/proxybroker2.git"}


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

run pip list in virtual env:

Package            Version
------------------ ---------
aiodns             3.0.0
aiohttp            3.8.3
aiosignal          1.2.0
async-timeout      4.0.2
attrs              22.1.0
cachetools         5.2.0
certifi            2022.9.24
cffi               1.15.1
charset-normalizer 2.1.1
click              8.1.3
colorama           0.4.6
frozenlist         1.3.1
idna               3.4
maxminddb          2.2.0
multidict          6.0.2
pip                22.2.2
proxybroker        2.0.0a4
pycares            4.2.2
pycparser          2.21
setuptools         65.3.0
wheel              0.37.1
wincertstore       0.2
yarl               1.8.1

I'm not sure that is a bug or something I miss. Somebody can help?

@ziloka
Copy link

ziloka commented Nov 4, 2022

This seems to work

"""Find and show 10 working HTTP(S) proxies."""

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()
loop = asyncio.get_event_loop_policy().get_event_loop()
broker = Broker(proxies, loop=loop)
tasks = asyncio.gather(broker.find(types=['HTTP', 'HTTPS'], limit=10), show(proxies))

loop.run_until_complete(tasks)

image

@ziloka
Copy link

ziloka commented Nov 4, 2022

the reason is because you need to pass the loop into the Broker constructor.

On python 3.10 it seems like theres a deprecation warning that I did not think of previously

@ziloka
Copy link

ziloka commented Nov 4, 2022

a2715be

now that i think about it, i unintentionally broke the examples

@ziloka
Copy link

ziloka commented Nov 4, 2022

so the example actually works, i just need a change to be made to fix the thing I didn't know i broke

@ziloka
Copy link

ziloka commented Nov 4, 2022

Related #110

Merge this and the basic example should work without any changes

EDIT: tested on 3.8, and 3.10

@bluet
Copy link
Owner

bluet commented Nov 4, 2022

Merged 👍

@Roboxkin
Copy link

"""Find and show 10 working HTTP(S) proxies."""

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()
loop = asyncio.get_event_loop_policy().get_event_loop()
broker = Broker(proxies, loop=loop)
tasks = asyncio.gather(broker.find(types=['HTTP', 'HTTPS'], limit=10), show(proxies))

loop.run_until_complete(tasks)

AttributeError: 'TransportSocket' object has no attribute 'close'
Exception ignored in: <function _SelectorTransport.del at 0x0000022F4DA47060>
Traceback (most recent call last):
File "C:\Users\Javascript\AppData\Local\Programs\Python\Python311\Lib\asyncio\selector_events.py", line 836, in del
self._sock.close()

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

5 participants