Proxy Support
# apify-platform
a
Is this the right away to add proxy support to an Actor? I'm guessing this is using the datacenter proxies included in my plan? Would users would be able to buy their own proxies and it would work? Or does the groups need to somehow get the proxy group name they purchased?
Copy code
python

            proxy_configuration = await Actor.create_proxy_configuration(
                groups=['BUYPROXIES94952'],
                country_code='US'
            )
            proxy_url = await proxy_configuration.new_url()
            Actor.log.info(f'Using proxy URL: {proxy_url}')

            async with AsyncClient(timeout=30.0) as client:
                transport = client._transport  
                transport.proxies = {'http': proxy_url, 'https': proxy_url}
h
Someone will reply to you shortly. In the meantime, this might help: -# This post was marked as solved by Matous. [View answer]().
l
I think that will work, but if you just want to use the datacenter proxies, that is the default. So you could also write it like this.
Copy code
javascript
const proxyConfiguration = await Actor.createProxyConfiguration();

const crawler = new CheerioCrawler({
  // ...
  proxyConfiguration,
  requestHandler({ proxyInfo }) {
     const usedProxyUrl = proxyInfo.url; // Getting the proxy URL
  }
})
Documentation: https://docs.apify.com/sdk/js/reference/class/ProxyConfiguration
a
Thanks, how do I allow any type of proxy? Is hard coding the groups going to force a type?
l
You mean both residential and data center? That's not a common use case and there's no easy way to do that. I think you would have to get all of the proxy URLs dynamically and feed them to the proxy config. Be aware that you will pay based on the GB sent through the residential proxies, so might be expensive. If you just want to allow all datacenter proxies, there's nothing to do. By not providing any groups that will happen automatically.