Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 1088

HELP WITH AIOHTTP

by PepeArgento - 05 January, 2023 - 12:36 PM
This post is by a banned member (PepeArgento) - Unhide
412
Posts
21
Threads
4 Years of service
#1
(This post was last modified: 05 January, 2023 - 02:37 PM by PepeArgento. Edited 3 times in total.)
I am working on an asynchronous proxy checker and when it has to test many proxies the script never works.
 when there are few proxies, it works.


async def check(client, proxy):
url = 'http://www.google.com/'
proxies = ('http://' + proxy)
try:
r = await client.get(url, proxy=proxies, timeout=10)
r.close()
print(f'''G00D {proxy}''')
return proxy
except:
pass

async def check1():
async with sem:
async with aiohttp.ClientSession() as client:
tasks = []
g00d = []
for proxy in protsies:
task = asyncio.ensure_future(check(client, proxy))
tasks.append(task)
results = await asyncio.gather(*tasks)


for proxy in results:
if proxy != None:
g00d.append(proxy)
return g00d






IGNORE VARIABLE NAMES
[Image: giphy.gif]
This post is by a banned member (Bloodhoundr) - Unhide
This post is by a banned member (PepeArgento) - Unhide
412
Posts
21
Threads
4 Years of service
#3
(05 January, 2023 - 01:51 PM)Bloodhoundr Wrote: Show More
How are we supposed to help you if you don't share your code? Shrug

UPDATED
[Image: giphy.gif]
This post is by a banned member (Cybe3r00rt) - Unhide
21
Posts
0
Threads
2 Years of service
#4
One solution could be to use a Semaphore to limit the number of concurrent requests that are sent through your network connection. In this way, you can control the amount of traffic that is passing through your network and avoid overloading it.


import asyncio
import aiohttp

# Crea un Semáforo con un límite de 10 solicitudes concurrentes
sem = asyncio.Semaphore(10)

async def check(client, proxy):
    url = 'http://www.google.com/'
    proxies = ('http://' + proxy)
    try:
        async with sem:
            r = await client.get(url, proxy=proxies, timeout=10)
            r.close()
        print(f'''G00D {proxy}''')
        return proxy
    except:
        pass

async def check1():
    async with aiohttp.ClientSession() as client:
        tasks = []
        g00d = []
        for proxy in protsies:
            task = asyncio.ensure_future(check(client, proxy))
            tasks.append(task)
        results = await asyncio.gather(*tasks)

        for proxy in results:
            if proxy != None:
                g00d.append(proxy)
        return g00d

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)