curl to Python requests
Convert a curl command into Python requests code, with headers, JSON body, form data, auth and cookies carried over.
Set up for this job. It runs on curl to fetch converter, where every option is there to change.
Questions
What does the Python code need?
The requests library (pip install requests). The code imports it, sends the request and prints the status code and the response text.
How is a JSON body sent?
When the body is valid JSON it becomes a Python dict passed as json=, and requests sets the Content-Type header itself, so that header is left out of the headers dict.
What happens to -k, -m and -u?
-k becomes verify=False, -m becomes timeout= in seconds and -u becomes auth=(user, password). Options with no requests equivalent are listed in the notes.
Does it run the request?
No. It only rewrites the command as code. Nothing is sent, so tokens and cookies in the command stay on your device.