# How to Convert a cURL Command into Python, Node or PHP Code with Proxy Support

[All guides](https://proxylane.dev/blog) 

GUIDES & FIELD NOTES · 13 MIN READ

We will use real tools like curlconverter, Postman snippets, and advanced.name’s cURL converter, and then harden the output so it works reliably with…

[**Victor Paulius** Tech Writer at ProxyLane](https://proxylane.dev/about/victor)   PublishedNov 29, 2026

On this page [Prerequisites](https://proxylane.dev/blog/convert-curl-python-proxy#prerequisites)  [Step 1: Start from a clean proxy-enabled cURL command](https://proxylane.dev/blog/convert-curl-python-proxy#step-1-start-from-a-clean-proxy-enabled-curl-command)  [Step 2: Convert the cURL command with a cURL converter tool](https://proxylane.dev/blog/convert-curl-python-proxy#step-2-convert-the-curl-command-with-a-curl-converter-tool)  [Step 3: Harden the Python Requests code (with proxy and session)](https://proxylane.dev/blog/convert-curl-python-proxy#step-3-harden-the-python-requests-code-with-proxy-and-session)  [Step 4: Convert to Node (Axios and Fetch/Undici) with proxy support](https://proxylane.dev/blog/convert-curl-python-proxy#step-4-convert-to-node-axios-and-fetchundici-with-proxy-support)  [Step 5: Convert to PHP cURL with explicit proxy options](https://proxylane.dev/blog/convert-curl-python-proxy#step-5-convert-to-php-curl-with-explicit-proxy-options)  [Step 6: Verify that proxy, auth, headers, and cookies survived the conversion](https://proxylane.dev/blog/convert-curl-python-proxy#step-6-verify-that-proxy-auth-headers-and-cookies-survived-the-conversion)  [Step 7: Plug in a production residential proxy provider](https://proxylane.dev/blog/convert-curl-python-proxy#step-7-plug-in-a-production-residential-proxy-provider)  [FAQ: Troubleshooting cURL-to-code conversions with proxies](https://proxylane.dev/blog/convert-curl-python-proxy#faq-troubleshooting-curl-to-code-conversions-with-proxies)

About ProxyLane  

- **Ethically sourced**Real residential devices, not datacenter ranges
 
- **Low fraud scores**98.7% low-risk IPs on Scamalytics
 
- **28M+ IPs in 195 countries**Country, city and ISP targeting

  [How we source and check IPs](https://proxylane.dev/about#trust-center)

 

By the end of this tutorial, you will be able to take a proxy-enabled `curl` command and turn it into production-ready Python, Node, or PHP code that:

 

- Preserves residential proxy authentication
 
- Keeps headers and cookies for logged‑in sessions
 
- Behaves predictably for AI agents and scraping workflows

 

We will use real tools like curlconverter, Postman snippets, and advanced.name’s cURL converter, and then harden the output so it works reliably with residential proxy providers and AI pipelines.

  

This guide is the hands-on companion to our in-depth explainer, What a cURL converter is and how it works.

   

## Prerequisites

 

Before you start, you should have:

 

- A proxy-enabled `curl` command (we’ll build one together in Step 1)
 
- Basic familiarity with a command line interface (CLI)
 
- One of these languages installed: 

- Python 3.9+
 
- Node.js 18+ (for `fetch` / Undici and Axios examples)
 
- PHP 8+ (with cURL extension enabled)
 
- A working HTTP or SOCKS5 proxy, for example a residential proxy from a provider like ProxyLane
 
- Optional but recommended tools: 

- A browser-based converter: **curlconverter**, **Postman “curl to Code”**, or **advanced.name cURL converter**
 
- A test target URL you are allowed to access (e.g. your own account page or a test API)

 

Common failure at this stage

 

- Starting with a `curl` copied from DevTools that contains your real session cookies or `Authorization` headers. Never paste those into online tools or share them.

  

## Step 1: Start from a clean proxy-enabled cURL command

 

To convert correctly, you first need a **minimal, explicit cURL command** that includes:

 

- Target URL
 
- Proxy server, including auth
 
- Headers you actually need
 
- Cookies or tokens (only if you’re keeping them **locally**, not sending to any web service)

 

### 1.1 Sample residential proxy cURL command

 

This example uses an HTTP residential proxy with username/password auth:

 

```bash
curl 'https://example.com/account' \
  -x 'http://username:password@proxy.example.net:8000' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)' \
  -H 'Accept: text/html,application/xhtml+xml' \
  -H 'Accept-Language: en-US,en;q=0.9' \
  -H 'Referer: https://example.com/login' \
  -b 'sessionid=abc123' \
  --compressed \
  --max-time 30
```

 

Key flags for proxy workflows:

 

- `-x` / `--proxy`: sets proxy, including protocol
 
- `-H`: headers; often critical for bot detection
 
- `-b`: cookies; used for logged-in sessions
 
- `--compressed`: accept gzip/deflate
 
- `--max-time`: timeout in seconds

 

### 1.2 Clean sensitive data before using cURL converters

 

If you use a browser-based curl converter:

 

- Replace real values with placeholders like `username`, `password`, `sessionid=...`
 
- Or remove cookies and `Authorization` headers entirely, then reinsert them **locally in code** after conversion

 

Common failure

 

- Forgetting that DevTools “Copy as cURL” includes `Cookie:` and `Authorization:` headers, which can let others log in as you. advanced.name explicitly warns about this; treat your cURL just like a password.

  

## Step 2: Convert the cURL command with a cURL converter tool

 

Modern cURL converters save time by generating starter code for you.

 

Popular options:

 

- **curlconverter**: open-source, supports 27+ languages (Python, JavaScript, Node, PHP and more). Conversion happens in your browser.
 
- **Postman code snippets**: supports 30+ language/client combinations including Python Requests, Axios, and PHP cURL.
 
- **advanced.name cURL converter**: specialized UI with explicit **proxy field** support; can override `-x` and adds SOCKS5 dependencies for Python/Node.

 

### 2.1 Use curlconverter for quick Python / Node / PHP code

 

1. Open the curlconverter site.
 
1. Paste your cleaned cURL command.
 
1. Pick your target: 

- `python-requests`
 
- `node-axios` or `node-fetch`
 
- `php-curl`
 
1. Copy the generated snippet.

 

Curlconverter notes that:

 

- It understands all 255 `curl` arguments but ignores many that don’t map directly.
 
- It is **not a perfect semantic clone** of cURL; it keeps the runtime defaults (e.g. redirects) unless you change them.

 

### 2.2 Use Postman or advanced.name when you need proxy-specific controls

 

- **Postman**: 

- Import your cURL as a request
 
- Use “Code” to generate snippets (Python Requests, Node Axios, JS Fetch, PHP Guzzle, PHP cURL, etc.)
 
- **advanced.name**: 

- Paste your cURL
 
- Optionally fill the separate proxy field (`http://user:pass@host:port`) — this can override your `-x` flag
 
- Choose Python, Node.js or PHP

 

Common failure

 

- Assuming the generated code includes proxy behavior when your original cURL did **not** have `-x` or a proxy field. Always check that the output actually routes through your proxy.

  

## Step 3: Harden the Python Requests code (with proxy and session)

 

Python Requests is a strong default for production-grade scraping and AI-agent workflows because the `Session` object gives you:

 

- Cookie persistence
 
- Connection pooling
 
- Shared proxy configuration

 

### 3.1 Example: cURL to Python Requests with proxy authentication

 

Starting from the cURL in Step 1, a good Python translation might look like this:

 

```python
import requests
from requests.auth import HTTPProxyAuth

proxies = {
    "http": "http://proxy.example.net:8000",
    "https": "http://proxy.example.net:8000",
}

proxy_auth = HTTPProxyAuth("username", "password")

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
    "Accept": "text/html,application/xhtml+xml",
    "Accept-Language": "en-US,en;q=0.9",
    "Referer": "https://example.com/login",
}

cookies = {
    "sessionid": "abc123",
}

session = requests.Session()
session.headers.update(headers)
session.proxies.update(proxies)
session.auth = None            # origin auth (if needed) goes here

response = session.get(
    "https://example.com/account",
    cookies=cookies,
    timeout=30,
    auth=proxy_auth,            # proxy authentication
    allow_redirects=False       # match curl (no -L)
)

print(response.status_code)
print(response.text[:500])
```

 

Notes:

 

- `proxies` maps scheme to proxy URL.
 
- `HTTPProxyAuth` is used when the proxy demands `username:password`.
 
- `allow_redirects=False` matches cURL’s default (cURL does **not** follow redirects unless you use `-L`).

 

### 3.2 Keep headers and cookies for logged-in sessions

 

When converting authenticated flows:

 

- Put **stable headers** (User-Agent, Accept, Referer) into `session.headers`.
 
- Pass cookies explicitly to `session.get()` / `post()` or use `session.cookies` if you know they’ll change.

 

Common failure

 

- Forgetting to use `requests.Session()`. Without a session, you lose cookie persistence and connection pooling, which breaks authenticated scraping and AI agents that need the same session over many requests.

  

## Step 4: Convert to Node (Axios and Fetch/Undici) with proxy support

 

Node’s modern HTTP stack is built on **Undici**, which powers `fetch` in recent Node versions. For scraping and AI agents, two common clients are:

 

- **Axios** (feature-rich, easy proxy config)
 
- **Native fetch with Undici’s proxy agents** (modern, standards-based)

 

### 4.1 Example: cURL to Node with Axios and HTTP proxy auth

 

```js
import axios from "axios";

const agent = axios.create({
  baseURL: "https://example.com",
  timeout: 30000,
  headers: {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
    "Accept": "text/html,application/xhtml+xml",
    "Accept-Language": "en-US,en;q=0.9",
    "Referer": "https://example.com/login",
  },
  // Axios proxy config
  proxy: {
    protocol: "http",
    host: "proxy.example.net",
    port: 8000,
    auth: {
      username: "username",
      password: "password",
    },
  },
  maxRedirects: 0, // match curl without -L
});

async function main() {
  const response = await agent.get("/account", {
    headers: {
      Cookie: "sessionid=abc123",
    },
  });

  console.log(response.status, response.data.slice(0, 500));
}

main().catch(console.error);
```

 

Important Axios proxy details:

 

- `proxy` config builds a CONNECT tunnel for HTTPS targets.
 
- `auth` inside `proxy` is for **proxy authentication**.
 
- Axios’s top-level `auth` option is for HTTP Basic to the **origin server**, not for bearer tokens. Use `Authorization: 'Bearer ...'` in headers for tokens.

 

### 4.2 Example: Node fetch with Undici’s proxy agent (HTTP or SOCKS5)

 

For longer-running AI agents, you may prefer native fetch with Undici’s agents:

 

```js
import { ProxyAgent, fetch } from "undici";

const proxyUrl = "http://username:password@proxy.example.net:8000";

const proxyAgent = new ProxyAgent(proxyUrl);

async function main() {
  const response = await fetch("https://example.com/account", {
    dispatcher: proxyAgent,
    headers: {
      "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
      "Accept": "text/html,application/xhtml+xml",
      "Accept-Language": "en-US,en;q=0.9",
      "Referer": "https://example.com/login",
      "Cookie": "sessionid=abc123",
    },
  });

  console.log(response.status);
  const text = await response.text();
  console.log(text.slice(0, 500));
}

main().catch(console.error);
```

 

For SOCKS5 proxies, Undici also exposes `SocksProxyAgent` / `Socks5ProxyAgent` which support username/password auth and delegate DNS resolution to the proxy.

 

Common failure

 

- Relying only on `HTTP_PROXY` / `HTTPS_PROXY` environment variables and assuming your Node client respects them. Axios documents env var handling and `NO_PROXY`, but not all clients do; always verify proxy routing explicitly.

  

## Step 5: Convert to PHP cURL with explicit proxy options

 

PHP’s cURL extension is built directly on libcurl, so it maps closely to `curl` flags. You configure it via `curl_setopt` calls.

 

### 5.1 Example: cURL to PHP with proxy, auth, headers, and cookies

 

```php
<?php

$ch = curl_init();

curl_setopt_array($ch, [
    CURLOPT_URL => 'https://example.com/account',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',           // allow gzip/deflate
    CURLOPT_MAXREDIRS => 0,           // match curl without -L
    CURLOPT_TIMEOUT => 30,

    // Proxy settings
    CURLOPT_PROXY => 'http://proxy.example.net:8000',
    CURLOPT_PROXYUSERPWD => 'username:password',

    // Headers
    CURLOPT_HTTPHEADER => [
        'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
        'Accept: text/html,application/xhtml+xml',
        'Accept-Language: en-US,en;q=0.9',
        'Referer: https://example.com/login',
        'Cookie: sessionid=abc123',
    ],
]);

$response = curl_exec($ch);

if ($response === false) {
    $error = curl_error($ch);
    $errno = curl_errno($ch);
    curl_close($ch);
    die("cURL error $errno: $error\n");
}

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "Status: $httpCode\n";
print substr($response, 0, 500);
```

 

Key options:

 

- `CURLOPT_PROXY`: proxy URL; supports HTTP, HTTPS, SOCKS5, etc.
 
- `CURLOPT_PROXYUSERPWD`: `username:password` for proxy authentication.
 
- `CURLOPT_HTTPHEADER`: explicit headers.
 
- `CURLOPT_ENCODING`: empty string means “any encoding”; allows gzip.

 

Common failure

 

- Forgetting `CURLOPT_RETURNTRANSFER`. Without it, `curl_exec` prints the output directly instead of returning it, which makes debugging and structured scraping harder.

  

## Step 6: Verify that proxy, auth, headers, and cookies survived the conversion

 

Once you have code in Python, Node, or PHP, you must confirm that everything behaves like your original cURL run.

 

### 6.1 Check that traffic actually goes through the proxy

 

Use a simple “what is my IP” endpoint that you are allowed to hit, ideally from the same country as your residential IP.

 

Change your URL temporarily to something like:

 

```text
https://api.ipify.org?format=json
```

 

Run your Python / Node / PHP script and confirm that:

 

- The IP matches the proxy provider, not your server
 
- The geolocation (country, city) matches what you ordered

 

### 6.2 Confirm headers and cookies

 

On a test endpoint you control, log the incoming request:

 

- Check `User-Agent`, `Accept`, `Referer`, and custom headers
 
- Check the `Cookie` header or any session behavior

 

If you don’t control an endpoint, you can temporarily:

 

- Use a request inspector like RequestBin or webhook.site (without real cookies or tokens)
 
- Or enable server logs on a dev environment

 

### 6.3 Validate redirect and TLS behavior

 

Remember:

 

- cURL does **not** follow redirects by default; Requests, Axios, and fetch often do
 
- TLS defaults (cipher suites, SNI) may differ between runtimes

 

Align behavior explicitly:

 

- Python: `allow_redirects=False` to match cURL without `-L`
 
- Axios: `maxRedirects: 0` to disable redirects
 
- PHP: `CURLOPT_FOLLOWLOCATION` if you want redirects

 

Common failure

 

- Skipping this verification step and later discovering that your AI agent or scraper does not stay logged in because cookies, proxy settings, or redirects diverged from the working cURL.

  

## Step 7: Plug in a production residential proxy provider

 

Once your converted code works, you can connect it to a production residential proxy or mobile proxy service.

 

For authenticated workflows (logins, AI agents, e‑commerce), you typically want:

 

- **Residential proxies** with low risk scores and high success rate, so you pay for fewer blocked requests
 
- **Sticky sessions** (up to hours) so your agent looks like the same user over time
 
- **Precise geotargeting** (city, ZIP, ISP, ASN) so the website sees the right location

 

A provider like ProxyLane offers:

 

- Prime Lane: 28M+ residential IPs in 195 countries, 99.5% success rate, 0.35 s avg response time, and traffic that never expires
 
- Mobile Lane: real 4G/5G carrier IPs in 150+ countries for stricter sites
 
- Native ISP and dedicated US Mac Mini options for long-lived AI accounts

 

To try your converted code with real residential IPs, you can point your proxy settings at a gateway from a provider such as  [proxylane.dev](https://proxylane.dev)  and keep the rest of your code unchanged.

 

Common failure

 

- Choosing proxies only by “$ per GB” instead of success per finished page. Low-quality IPs that get blocked force retries and cost more in the long run, especially for AI agents.

  

## FAQ: Troubleshooting cURL-to-code conversions with proxies

 

### 1. Why does my Python / Node / PHP code not use the proxy even though cURL does?

 

Common causes:

 

- The converter ignored your `-x` flag or you removed it before conversion
 
- You put proxy settings in the wrong place (e.g. Axios `auth` instead of `proxy.auth`)
 
- Your runtime is using `NO_PROXY` environment variable to bypass the proxy for certain hosts

 

Fix:

 

- Verify proxy config explicitly in code (Requests `proxies`, Axios `proxy`, Undici `ProxyAgent`, PHP `CURLOPT_PROXY`)
 
- Test against an IP-echo service and confirm the observed IP matches your proxy provider

 

### 2. After conversion, redirects behave differently than in cURL. Why?

 

Because runtimes have different defaults:

 

- cURL does not follow redirects without `-L`
 
- Python Requests follows redirects by default
 
- Axios also follows redirects (up to `maxRedirects`)

 

Fix:

 

- Set redirect options explicitly: 

- Requests: `allow_redirects=False`
 
- Axios: `maxRedirects: 0`
 
- PHP: `CURLOPT_FOLLOWLOCATION` true/false

 

### 3. My logged-in scraping works in cURL but not in Python/Node/PHP. What changed?

 

Likely issues:

 

- Cookies from DevTools-copied cURL didn’t make it into your code
 
- Headers like `User-Agent` or `Referer` were dropped by the converter
 
- You are not using a persistent session (`requests.Session`, Axios instance, or cookie jar)

 

Fix:

 

- Manually port over `Cookie` and critical headers
 
- Use a session abstraction (Requests `Session`, Axios instance, PHP cookie jar if needed)
 
- Verify with server logs or a request inspector

 

### 4. How do I convert a SOCKS5 cURL proxy to Python or Node?

 

In cURL:

 

```bash
curl 'https://example.com' \
  -x 'socks5h://username:password@socks-proxy.example.net:1080'
```

 

In Python:

 

- Use `requests[socks]` and `socks5h://` in the proxy URL

 

```python
proxies = {
    "http": "socks5h://username:password@socks-proxy.example.net:1080",
    "https": "socks5h://username:password@socks-proxy.example.net:1080",
}
```

 

In Node:

 

- Use Undici’s `SocksProxyAgent` or community packages like `socks-proxy-agent`

 

### 5. Is it safe to paste cURL commands with cookies and tokens into online converters?

 

Treat any cURL containing `Cookie:`, `Authorization:`, or other secrets as sensitive:

 

- Tools like curlconverter say conversion happens completely in the browser, but you should still avoid sharing real session data
 
- advanced.name explicitly advises stripping cookies and authorization before sharing

 

Best practice:

 

- Replace secrets with placeholders before using web tools
 
- Insert real secrets into your local code via environment variables or a secret manager

  

With these steps, you have a repeatable process to convert a proxy-enabled cURL command into robust Python, Node, or PHP code that preserves your residential proxy settings, authentication, and headers for production-grade scraping and AI agent workflows.

 

ProxyLane  Traffic never expires

 

## [Premium residential proxies](https://proxylane.dev/residential-proxies) From $2/GB

 

Scale your workflows with the tools you already use. Rotating or sticky sessions up to 72 hours.

 

[Try 350 MB for $1.95](https://proxylane.dev/register?interest=proxies&plan=trial)   [View plans](https://proxylane.dev/pricing)

## Keep reading

[Use cases · 4 min read

### Amazon Scraper API vs Proxy: Choose a Product Data Source

Compare seller APIs, licensed Amazon product data and proxy page checks by record, access scope and reuse rights.

 Read guide](https://proxylane.dev/blog/amazon-scraper-api-vs-proxy)   [Integration guides · 5 min read

### Antidetect browser proxy setup: choose a profile guide

Choose the right anti-detect browser proxy guide, map the shared verification steps, and keep account access separate from the network route.

 Read guide](https://proxylane.dev/blog/antidetect-browser-proxy-setup)   [Guides & field notes · 14 min read

### BeautifulSoup Python scraping with residential proxies: ProxyLane review, pricing & patterns that survive change

Python BeautifulSoup scraping still starts with requests + bs4, but durable, logged‑in workflows now live or die on the proxy layer. This guide shows how to…

 Read guide](https://proxylane.dev/blog/beautifulsoup-python-scraping-patterns-that-pair-well-with-residential-proxies)

Canonical source: https://proxylane.dev/blog/convert-curl-python-proxy

Documentation index: https://proxylane.dev/llms.txt
