Skip to main content
KalkuNet

cURL to Python and Go — requests and net/http Code from a curl Command

Translate HTTP curl commands directly into idiomatic Python requests & Go code.

Runs in your browserDeveloper · Formatters, Minifiers & Code Builders
Language:
MethodPOST
URLhttps://example.com/api/v1/tiket?status=buka
HeadersAccept: application/json
X-Request-Id: 7f3c-uji
Authorization: Basic YWRtaW46cmFoYXNpYQ==
Content-Type: application/x-www-form-urlencoded
Bodyjudul=Wi-Fi+lantai+2+mati&catatan=AP+%22lobby%22+%26+ruang+rapat
  • The command is read the way a shell reads it: single and double quotes, backslashes, continuation lines and $'…'. Combined options such as -sSL or -XPOST, repeated -d (joined with &), -G, --json, -F, -u, -b, -A and -e follow curl's own rules.
  • Headers curl adds on its own are written too, such as Content-Type application/x-www-form-urlencoded for -d and Authorization Basic for -u, so the server receives the same request. Testing sends real curl and the generated code to a test server and compares the requests it receives.

When to use the curl Command to Python requests & Go net/http Converter

  • Correct Python requests code

    The body is sent as UTF-8 bytes, non-ASCII headers are written as bytes, multipart forms use files, and allow_redirects=False is used when the command has no -L, because requests follows redirects by default while curl does not.

  • A complete Go program

    The Go output is a whole program with package main, imports, http.NewRequest, every header, multipart.Writer for forms and a client with CheckRedirect, InsecureSkipVerify or Timeout when the command asks for them. Every error is checked.

  • curl options read by its own rules

    Combined options such as -sSL or -XPUT, repeated -d, --data-urlencode, -G, --json, -F, -u, -b, -A, -e and --oauth2-bearer are translated by curl's own rules, including the Content-Type curl adds by itself.

  • Tested against real curl

    Testing runs the real curl command and the generated Python code against the same test server and compares the method, URL, headers and body received. The Go output is checked through the string values in its code.

Frequently asked questions

What about files from -F?

The code opens the file with the same name; make sure it exists in the program's working folder.

Is -k supported?

Yes. Python uses verify=False and Go uses InsecureSkipVerify. Use it only to test your own server.

Which Python and Go versions are needed?

The Python code uses the requests library, installed with pip install requests. The Go program uses only the standard library, so it runs straight away with go run.

Can a header repeat?

Yes. The values are joined with commas the way a server reads them, and cookies are joined with semicolons.

Is my command run?

No. The command is only read and converted in your browser.

Learn more