Skip to content

Use a proxy in Playwright, Puppeteer, Selenium, curl and Python

Every tool has its own way to set a proxy, and most have a quirk or two. This guide gives a working example for curl, Python requests, Playwright, Puppeteer and Selenium, with a one-line check that the traffic really leaves through your phone.

  • By FalconProxy
  • Reviewed
  • 4 min read
On this page
  1. 01Before you start
  2. 02curl
  3. 03Python requests
  4. 04Playwright
  5. 05Puppeteer
  6. 06Selenium
  7. 07Check that it works

Before you start

You need a working proxy and its credentials from the Access panel. If you do not have one yet, the guide on turning an Android phone into a mobile proxy takes you through it. The examples use placeholders: replace USERNAME and PASSWORD with your own values. With a username and password the HTTP endpoint is api.falconproxy.com:8080 and the SOCKS5 endpoint is api.falconproxy.com:1080. With an allowed IP address, use the dedicated endpoints the panel shows.

  • Playwright
  • Puppeteer
  • Selenium
  • curl
  • Python

One proxy

Your phone, through FalconProxy

Endpoints

api.falconproxy.com:8080api.falconproxy.com:1080

HTTP and SOCKS5

Whichever tool sends the request, it reaches the same proxy, so the website sees the same exit address.
Which endpoint each tool uses
ToolEndpointSign-in
curlHTTP or SOCKS5Username and password, or an allowed IP address.
Python requestsHTTP or SOCKS5Username and password in the proxy URL.
PlaywrightHTTPUsername and password in their own fields.
PuppeteerHTTPA call to page.authenticate.
Selenium with ChromeHTTPAn allowed IP address: Chrome ignores credentials in the proxy flag.

curl

HTTP

shell
curl -x http://USERNAME:PASSWORD@api.falconproxy.com:8080 https://api.ipify.org

SOCKS5

shell
curl --proxy socks5h://USERNAME:PASSWORD@api.falconproxy.com:1080 https://api.ipify.org

A password with special characters is easier to pass with --proxy-user, because both the shell and a URL treat some characters specially. Put the password in single quotes:

shell
curl -x http://api.falconproxy.com:8080 --proxy-user 'USERNAME:PASSWORD' https://api.ipify.org

To use the proxy for every curl command in a shell session, set an environment variable. curl reads https_proxy, http_proxy and all_proxy.

shell
export https_proxy="http://USERNAME:PASSWORD@api.falconproxy.com:8080"
curl https://api.ipify.org

Python requests

python
import requests

proxy = "http://USERNAME:PASSWORD@api.falconproxy.com:8080"
proxies = {"http": proxy, "https": proxy}

response = requests.get("https://api.ipify.org", proxies=proxies, timeout=30)
print(response.text)

Always pass a timeout. Without one, a request through a phone that has dropped off can wait for a very long time. To reuse connections across many requests, set the proxies on a session:

python
session = requests.Session()
session.proxies.update(proxies)
print(session.get("https://api.ipify.org", timeout=30).text)

For SOCKS5, install the extra that adds support and use socks5h, so the name lookup also goes through the proxy:

shell
pip install "requests[socks]"
python
proxy = "socks5h://USERNAME:PASSWORD@api.falconproxy.com:1080"

Playwright

Put the credentials in the username and password fields. Playwright drops credentials written inside the server URL, and the proxy then answers 407. The same proxy option also takes a bypass list of hosts that should not use the proxy, such as localhost.

Python

python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(
        proxy={
            "server": "http://api.falconproxy.com:8080",
            "username": "USERNAME",
            "password": "PASSWORD",
        }
    )
    page = browser.new_page()
    page.goto("https://api.ipify.org")
    print(page.inner_text("body"))
    browser.close()

Node.js

javascript
import { chromium } from 'playwright'

const browser = await chromium.launch({
  proxy: {
    server: 'http://api.falconproxy.com:8080',
    username: 'USERNAME',
    password: 'PASSWORD',
  },
})
const page = await browser.newPage()
await page.goto('https://api.ipify.org')
console.log(await page.innerText('body'))
await browser.close()

Puppeteer

Puppeteer takes the proxy as a browser flag and the credentials in a separate call on the page. Call page.authenticate before the first page.goto, and call it again on every new page, because the credentials belong to the page and not to the browser.

javascript
import puppeteer from 'puppeteer'

const browser = await puppeteer.launch({
  args: ['--proxy-server=http://api.falconproxy.com:8080'],
})
const page = await browser.newPage()
await page.authenticate({ username: 'USERNAME', password: 'PASSWORD' })
await page.goto('https://api.ipify.org')
console.log(await page.evaluate(() => document.body.innerText))
await browser.close()

Selenium

Chrome ignores a username and password written in its --proxy-server flag, so with Selenium the dependable route is to sign in by IP address. In the proxy’s Access panel, choose IP whitelist and Manage whitelist, and add the public address of the machine that runs the browser. The panel then shows a dedicated HTTP endpoint for your proxy. Use it as HOST and PORT below; no credentials are needed.

python
from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://HOST:PORT")

driver = webdriver.Chrome(options=options)
driver.get("https://api.ipify.org")
print(driver.find_element(By.TAG_NAME, "body").text)
driver.quit()

If you need a username and password with Selenium, drive the browser with Playwright instead, which handles the sign-in itself.

Check that it works

Each example above prints the address a website sees. Run one without the proxy and compare: the two addresses should differ, and the one through the proxy should be your phone’s. For the carrier, the location and the name lookup, see the guide on checking a proxy’s exit IP, carrier and DNS.

Common browser errors
What you seeUsual causeWhat to do
net::ERR_PROXY_CONNECTION_FAILEDThe browser cannot reach the proxy.Check the host and the port, your network, and that the proxy’s status is Live.
net::ERR_TUNNEL_CONNECTION_FAILEDThe proxy refused the tunnel, often because the credentials did not arrive.Put the credentials in their own fields, or add your IP address to the allow list.
407 Proxy Authentication RequiredThe username or password is wrong, or was not sent.Copy them again from the Access panel.
  • Keep the credentials in environment variables or a secrets manager rather than in the script.
  • Close the browser when the job ends, so connections through the phone do not stay open.
FAQ

Questions, answered.

You cannot with Chromium: it has no username and password sign-in for SOCKS5, and Playwright refuses the combination. Use the HTTP endpoint with the username and password in their own fields, or use SOCKS5 with an allowed IP address and no password.

Playwright drops credentials written inside the server URL. Give the server as http://host:port and pass the username and password in their own fields.

Load an address-echo page such as api.ipify.org through the tool and again without the proxy. The two addresses should differ, and the one through the proxy should be your phone’s.

Ready to create your own proxies?

2-hour free trial, no card—pair your phone in minutes.

Already have an account? Sign in

FalconProxy