Skip to content

Create clients with a pool of proxies to sample from to save on creation time #3293

Answered by tomchristie
ff781 asked this question in Ideas
Discussion options

You must be logged in to vote

Here's a similar question... #2578 (comment)

I asked ChatGPT to give a quick pass on this...

Using Python's httpx write a custom transport that uses a rotating pool of proxies

Here's what it came back with...

import httpx
import itertools
from typing import List

class RotatingProxyTransport(httpx.BaseTransport):
    def __init__(self, proxies: List[str]):
        self.proxies = itertools.cycle(proxies)
        self._base_transport = httpx.HTTPTransport()
    
    def handle_request(self, request: httpx.Request) -> httpx.Response:
        # Get the next proxy from the cycle
        proxy = next(self.proxies)
        
        # Create a new transport with the current proxy
        with h…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by tomchristie
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants