I am starter to python and at the moment I am trying to get free proxies from proxybroker2, but I keep getting error straight for 4 days. I am using Quart + asyncio + proxybroker2. As shown below, my code doesn't work, I keep getting variety of different errors, all of them are related to loop, even more some of that times the app just hangs and nothing happens.
import asyncio
from proxybroker import Broker
from quart import jsonify, Blueprint
bp = Blueprint('free_proxies', __name__)
broker = Broker()
@bp.route('/find_proxies', methods=['GET'])
async def find_proxies():
try:
# Call the find method asynchronously
proxies = await asyncio.to_thread(
broker.find,
types=['HTTP', 'HTTPS'], # Modify the types as needed
limit=10 # Modify the limit as needed
)
# Collect the results in a list
all_proxies = []
while True:
proxy = await asyncio.to_thread(proxies.get)
if proxy is None:
break
all_proxies.append({
'host': proxy.host,
'port': proxy.port,
'type': proxy.schema,
'anonymity': proxy.anon,
})
return jsonify(all_proxies)
except Exception as e:
return jsonify({'error': str(e)})
from quart import Quart
from free_proxies.routes import bp as free_proxies_bp
app = Quart(__name__)
app.register_blueprint(free_proxies_bp)
if __name__ == '__main__':
app.run(debug=True)