Live data from Hacker News

Convert Curl Syntax to Python Requests

curl.trillworks.com

11–20 of 47 posts

Re: Convert Curl Syntax to Python Requests

#11
post #4

Failed entirely to work on my first attempt with: curl -XHEAD https://google.com It is just flat out wrong on: curl -X HEAD https://google.com In that it does a GET request: import requests response = requests.get('https://google.com/') Clever idea, but my first totally valid example failed (it does OPTIONS, GET, POST, PUT, PATCH successfully)

In case the creator of this tool doesn't read this thread, you can report the issues on GitHub: https://github.com/NickCarneiro/curlconverter/issues

Re: Convert Curl Syntax to Python Requests

#12
post #4

Failed entirely to work on my first attempt with: curl -XHEAD https://google.com It is just flat out wrong on: curl -X HEAD https://google.com In that it does a GET request: import requests response = requests.get('https://google.com/') Clever idea, but my first totally valid example failed (it does OPTIONS, GET, POST, PUT, PATCH successfully)

`curl --head` (short form: `-I`) is converted correctly though, and `curl -X HEAD` (or `-XHEAD`) does generate warnings telling you to use `--head`/`-I`.

Re: Convert Curl Syntax to Python Requests

#19
I've also written a tool that converts curl commands to Python Requests or JavaScript XMLHttpRequest code. It is tested with curl commands generated by Safari, Burp Suite, and Charles Proxy. It can also translate raw HTTP requests, so it can be used when you have a packet capture.

The design is modular and separates the frontend (curl) from the backend (Python), so more input and output formats can be added. It tries to be smart about generating "clean" code, so it will, for example, remove the Content-Length header when it can be recomputed from the request content.

https://ryan.govost.es/http-translator/

It is also open source. Feedback or pull requests are welcome. https://github.com/rgov/http-translator

Post reply on HN