Use proxies¶
Route requests through your own proxy pool to bypass IP-based block lists and bot detection.
Solution¶
Pass a list of proxy URLs when creating the client. Both fetchers (public JSON API and private HTML scraping) are enabled by default whenever a list is provided.
from pyventim import EventimClient, EventimMarket, EventimCategory
proxies = [
"http://proxy1.example.com:8080",
"http://user:pass@proxy2.example.com:3128",
]
client = EventimClient(
market=EventimMarket.GERMANY,
proxies=proxies,
)
for pg in client.product_groups(categories=[EventimCategory.CONCERTS], page_limit=1):
print(pg.name)
The public fetcher (httpx) picks a proxy at random on each call. The private fetcher
(Scrapling) cycles through the list in order using a
ProxyRotator.
Disable proxy for one fetcher¶
Use use_public_proxy or use_private_proxy at construction time to opt a specific
fetcher out while keeping the other proxied.
# Only proxy the private (HTML scraping) fetcher; public API calls go direct.
client = EventimClient(
market=EventimMarket.GERMANY,
proxies=proxies,
use_public_proxy=False,
use_private_proxy=True,
)
Disable proxy for a single call¶
Pass use_proxy=False to any method to bypass the proxy for that call only.
client = EventimClient(market=EventimMarket.GERMANY, proxies=proxies)
# This call goes through a proxy.
for attr in client.attractions("Metallica", page_limit=1):
print(attr.name)
# This call goes direct regardless of the configured proxy list.
for attr in client.attractions("Metallica", page_limit=1, use_proxy=False):
print(attr.name)
Notes¶
- Proxy URLs must include a scheme (
http://orhttps://). Credentials can be embedded in the URL ashttp://user:pass@host:port. - When no proxies are configured,
use_proxy=True(the default) is a no-op — all requests go direct. - The
use_public_proxy/use_private_proxyconstructor flags only take effect whenproxiesis notNone. - The random selection for the public fetcher is chosen once per method call, not
once per page. All pages in a single
product_groups()call, for example, use the same proxy.