Log in Sign up
cURL to code

Convert a cURL command to Python requests, axios or PHP

Right-click a request in browser DevTools, choose Copy as cURL and paste it here. You get Python requests, Node.js axios or PHP code with the same URL, headers, cookies and body, plus your proxy if you add one.

Language

The proxy field overrides -x and -U from the command and accepts ip:port:user:pass. For SOCKS5, the Python and Node.js code starts with the install line for the package you need.

A cURL command from the terminal turns into ready code

How the curl converter reads your command

The converter splits the command the way a shell does. It handles single and double quotes, $'...' strings and line breaks from bash (\), Windows cmd (^) and PowerShell (backtick), and the command may start with curl or curl.exe. Parsing and code generation run in your browser.

Pick one of three outputs: Python 3 with requests, Node.js with axios, or PHP with its curl extension (curl_init and curl_setopt). Switching tabs rebuilds the code from the same command.

Before writing code, the converter drops the Content-Length, Host and Accept-Encoding headers. The library works out length and host from the request. For compression, requests and axios ask for gzip on their own, and PHP gets CURLOPT_ENCODING when the command has --compressed. A Cookie header or -b value goes into a cookies dict in Python. axios gets it back as a Cookie header, and PHP gets CURLOPT_COOKIE.

When to convert curl to Python or Node.js

  • Your scraper has to send a request with the same headers and cookies the browser sent.
  • A request works in Postman or DevTools, and you want it in a script without retyping a dozen headers.
  • You compare how a site answers through a proxy and without one. Test the proxy in the online proxy checker first, so a dead IP does not look like a blocked request.
  • You set the User-Agent with -A and need a current browser string. The User-Agent generator gives you one.
  • You are learning requests or axios and want working code built from a request you know.

Example: cURL to Python requests

Press Example and the form loads a POST to https://httpbin.org/post with two headers (Accept and Content-Type: application/json), -b 'session=abc123', a --data-raw body of {"query":"proxy","page":1}, --compressed and a test proxy. The Python tab shows a headers dict with those two headers, cookies = {"session": "abc123"}, json_data = {"query": "proxy", "page": 1} and a proxies dict, then calls requests.post(url, headers=headers, cookies=cookies, json=json_data, proxies=proxies, allow_redirects=False). The code picks POST because the command has a body. --compressed adds no line here, since requests asks for gzip and unpacks the reply on its own. On the Node.js tab the same body turns into a JS object in data, next to an HttpsProxyAgent and maxRedirects: 0.

Supported curl flags in requests, axios and PHP

-X sets the method and -I sends HEAD. -H adds a header, and -A and -e turn into User-Agent and Referer headers. The body comes from -d, --data-raw, --data-binary and --data-urlencode; several -d values join with &. --json sets the body together with JSON Content-Type and Accept headers, and -G moves the data into the query string. -F name=value adds a form field, and -F file=@photo.jpg uploads a file: Python opens it into files=, axios appends it to a FormData, PHP wraps it in CURLFile. -u becomes auth= in requests, auth in axios and CURLOPT_USERPWD in PHP. -b sets cookies, -L turns on redirects and -k turns off certificate checks. -m sets the timeout, with --connect-timeout as a fallback when -m is absent. -x and -U carry the proxy and its login. Flags that change how curl itself saves output or retries, such as -o, -w and --retry, leave no trace in the code.

Using a proxy with Python requests and axios

The Proxy field takes ip:port, http://user:pass@ip:port, socks5://user:pass@ip:port or the ip:port:user:pass line many proxy sellers hand out. The converter rewrites ip:port:user:pass as http://user:pass@ip:port and URL-encodes the login and password, so a password with @ or # still works. Python gets a proxies dict with the same URL for http and https. axios gets an HttpsProxyAgent or SocksProxyAgent as httpAgent and httpsAgent, plus proxy: false, so axios ignores HTTP_PROXY variables from the environment. PHP passes the URL to CURLOPT_PROXY. For a SOCKS proxy the code opens with # pip install requests[socks] in Python or // npm install axios socks-proxy-agent in Node.js. To reformat a whole list, use the proxy list converter.

Questions about converting curl to code

01How do I copy a request as cURL in Chrome, Edge or Firefox?

Open DevTools with F12, go to the Network tab and right-click the request. Open the Copy submenu (Copy Value in Firefox) and pick Copy as cURL. On Windows, Chrome and Edge offer a cmd and a bash variant, and Firefox calls them Windows and POSIX. Pick bash or POSIX: it wraps values in single quotes and stays readable if you edit the command by hand.

02Does the command go to your server?

No. Parsing and code generation run in your browser, and neither the command nor the proxy goes anywhere.

03Why does the generated code not follow redirects?

curl without -L stops at the first 301 or 302, and the code keeps that behavior: allow_redirects=False in Python, maxRedirects: 0 in axios, no CURLOPT_FOLLOWLOCATION in PHP. axios also gets validateStatus: () => true, so a redirect reaches .then instead of throwing. Add -L to the command and the code follows redirects.

04How do I add an HTTP or SOCKS5 proxy with a login to Python requests or axios?

Type it in the Proxy field as http://user:pass@ip:port, socks5://user:pass@ip:port or ip:port:user:pass. You can also leave it in the command as -x ip:port with -U user:pass. Python gets a proxies dict and axios gets a proxy agent. For SOCKS5 the first line of the code names the package to install.

05What should I remove from a copied command before sharing the code?

The cookie and authorization headers and the -b flag. A command from DevTools carries your session cookies and tokens, and anyone can log in to your account with them.

06What do -k and -m change in the generated code?

-k (--insecure) turns off certificate checks: verify=False in requests, rejectUnauthorized: false in axios, CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST off in PHP. Use it against a test server with a self-signed certificate and remove it before production. -m 10 becomes timeout=10 in Python, timeout: 10000 in axios (milliseconds) and CURLOPT_TIMEOUT 10 in PHP. Without -m or --connect-timeout the code sets no timeout, and requests waits on a hung server with no limit.

07How does a JSON body become json= in requests?

The converter parses the body as JSON when the command sets a Content-Type header that contains json. Python then gets a json_data dict passed as json=, and axios gets a JS object in data. A body that fails to parse, or one sent without that header, stays a plain string: data= in Python, data in axios. PHP keeps the raw string in CURLOPT_POSTFIELDS either way. --json adds the header for you.

08Can I paste a curl command from Windows cmd or PowerShell?

Yes. The converter reads the cmd variant that Chrome and Edge copy, removing the ^ escapes and ^ line breaks, and it joins PowerShell lines that end in a backtick. In Windows PowerShell 5.1, curl is an alias for Invoke-WebRequest, so type curl.exe. Chrome's Copy as PowerShell produces Invoke-WebRequest code, which the converter cannot read.

Pricing Grab a free hour