TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Convert Curl Syntax to Python Requests

166 pointsby kapkapkapover 5 years ago

27 comments

NickC_devover 5 years ago
Author, here. curlconverter gets about 17k unique users per month. The code generated by this tool is probably in production all over the world.<p>But the codebase needs maintenance! I hired a junior developer (cf512) to do about 40 hours of dev work last month, but that contract has ended and I&#x27;d appreciate more volunteers. All the code is open source.<p>I see a few bug reports down thread. Please open tickets.<p>A big thanks to the top contributors, csells and jgroom33. Many others have pitched in over the last five years. Also, big thanks to Daniel Stenberg for writing curl in the first place.
评论 #21226812 未加载
评论 #21228249 未加载
kapkapkapover 5 years ago
I&#x27;m not the author of this tool, but I submitted it to HN because I just stumbled upon it after unsuccessfully trying to transpose a complicated cURL from Chrome devtools into python requests for a good 20 min. This worked instantly. Props to the author - <a href="https:&#x2F;&#x2F;twitter.com&#x2F;nickc_dev" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;nickc_dev</a>
评论 #21228228 未加载
vescheover 5 years ago
There&#x27;s a bit of a hidden feature in Postman that can do this and way more, hit the code button in the right corner and you can convert your web requests to something like a dozen languages: <a href="https:&#x2F;&#x2F;i.imgur.com&#x2F;0qUV8b9.png" rel="nofollow">https:&#x2F;&#x2F;i.imgur.com&#x2F;0qUV8b9.png</a>
评论 #21229111 未加载
rgovostesover 5 years ago
I&#x27;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.<p>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 &quot;clean&quot; code, so it will, for example, remove the Content-Length header when it can be recomputed from the request content.<p><a href="https:&#x2F;&#x2F;ryan.govost.es&#x2F;http-translator&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ryan.govost.es&#x2F;http-translator&#x2F;</a><p>It is also open source. Feedback or pull requests are welcome. <a href="https:&#x2F;&#x2F;github.com&#x2F;rgov&#x2F;http-translator" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rgov&#x2F;http-translator</a>
mycodebreaksover 5 years ago
Is it all client side?<p>I wonder how many cookies&#x2F;secret headers will be pasted by unaware and unknowing users.
kenover 5 years ago
This is neat, but also seems like a code smell. Do people really need to convert between HTTP request formats&#x2F;languages much? When I see many independent implementations of an N-to-M mapping, it looks like the perfect use case for a standardized interface, like a DSL.<p>In fact, can&#x27;t HAR do this? I&#x27;d love to be able to just pass a HAR string to any HTTP client library, and have it execute that. Or call &quot;dump_har()&quot; (or &quot;--dump-har&quot;) on any client, and have it spit out HAR that I can take it to any other client.
评论 #21226729 未加载
评论 #21229512 未加载
hkchadover 5 years ago
Postman also has the ability to import a curl command (from chrome dev tool) and then export to many programming languages.
northisupover 5 years ago
I made a similar library! <a href="https:&#x2F;&#x2F;github.com&#x2F;northisup&#x2F;curlit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;northisup&#x2F;curlit</a> (sorry for the poor documentation!)
40fourover 5 years ago
OK, I&#x27;m not going to lie. I didn&#x27;t even know you could copy requests from the network tab into curl (or fetch&#x2F; powershell&#x2F; etc.) like that. Embarrassing! :) Seems pretty useful!
评论 #21228882 未加载
fireattackover 5 years ago
This is especially handy on Windows, where Chrome failed to even produce proper cURL commands in CMD format [1].<p>[1]: <a href="https:&#x2F;&#x2F;bugs.chromium.org&#x2F;p&#x2F;chromium&#x2F;issues&#x2F;detail?id=658956" rel="nofollow">https:&#x2F;&#x2F;bugs.chromium.org&#x2F;p&#x2F;chromium&#x2F;issues&#x2F;detail?id=658956</a><p>[2]: <a href="https:&#x2F;&#x2F;bugs.chromium.org&#x2F;p&#x2F;chromium&#x2F;issues&#x2F;detail?id=798498" rel="nofollow">https:&#x2F;&#x2F;bugs.chromium.org&#x2F;p&#x2F;chromium&#x2F;issues&#x2F;detail?id=798498</a>
_wlduover 5 years ago
Here is a similar site that translates curl to Go:<p><a href="https:&#x2F;&#x2F;mholt.github.io&#x2F;curl-to-go&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mholt.github.io&#x2F;curl-to-go&#x2F;</a>
symmitchryover 5 years ago
Paw, which many people love, has a neat and similar feature: you can get extensions that convert the request you build in the app to any format: curl, python, etc.<p>It&#x27;s very handy.<p><a href="https:&#x2F;&#x2F;paw.cloud&#x2F;docs&#x2F;getting-started&#x2F;code-generator" rel="nofollow">https:&#x2F;&#x2F;paw.cloud&#x2F;docs&#x2F;getting-started&#x2F;code-generator</a>
scottehover 5 years ago
The &quot;uncurl&quot; library[1] does something similar and can be used in the terminal. I&#x27;ve found it extremely useful.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;spulec&#x2F;uncurl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;spulec&#x2F;uncurl</a>
m463over 5 years ago
I wrote a subroutine macos python to do the opposite.<p>On macos, requests is not included (although it can be installed with a little effort), but curl was there.<p>Note that you can easily automate interacting with a web page using the developer menus in safari and firefox.<p>monitor the network requests, then for the request you&#x27;re interested in, use &quot;copy as cURL&#x27;. You can copy&#x2F;paste that to invoke curl in the same way the web page used it.<p>(sometime I have to use --cookie-jar &#x2F;tmp&#x2F;cook --cookie &#x2F;tmp&#x2F;cook)
jchwover 5 years ago
Oh wow, not just Python - quire a wide array of languages are supported. Very nice, this will be handy for prototyping things.
keymoneover 5 years ago
reminds me of a little clojure macro i wrote to demonstrate &quot;power&quot; of macros in lisp: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;keymone&#x2F;d7725767dc0425a7bcf9" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;keymone&#x2F;d7725767dc0425a7bcf9</a>, obviously not feature-complete but sufficed for the demonstration
daolfover 5 years ago
For those interested in integrating such a feature on their website.<p>An helper for building API request, for example, there is this great open source project: <a href="https:&#x2F;&#x2F;github.com&#x2F;Kong&#x2F;apiembed&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Kong&#x2F;apiembed&#x2F;</a><p>It supports a dozen of language.
sikhnerdover 5 years ago
The capability to convert a network request from one format to another is the main reason I use Postman, which has a great implementation of this and a ton of tools and languages it can do it in. This looks great as well
faizshahover 5 years ago
This tool is incredibly useful, I use it at least once a week. Its incredibly useful to explore a site with network in devtools then be able to quickly turn it into a python prototype! Amazing work :)
pramttlover 5 years ago
Great tool, would be nice to also have a chrome extension for the same that augments dev-tools to reduce one extra step of copy&#x2F;paste.
SEJeffover 5 years ago
Failed entirely to work on my first attempt with:<p><pre><code> curl -XHEAD https:&#x2F;&#x2F;google.com </code></pre> It is just flat out wrong on:<p><pre><code> curl -X HEAD https:&#x2F;&#x2F;google.com </code></pre> In that it does a GET request:<p><pre><code> import requests response = requests.get(&#x27;https:&#x2F;&#x2F;google.com&#x2F;&#x27;) </code></pre> Clever idea, but my first totally valid example failed (it does OPTIONS, GET, POST, PUT, PATCH successfully)
评论 #21225674 未加载
评论 #21225573 未加载
评论 #21226712 未加载
agordhandasover 5 years ago
I independently used this tool a couple days ago. Helped save me a lot of debug time!
danielhlockardover 5 years ago
oh hey, I wrote the `Go` support for this tool.
评论 #21226855 未加载
runnr_azover 5 years ago
hey... that&#x27;s super handy. thx!
mleventalover 5 years ago
this is one of the most useful little tools on good&#x27;s green earth. I used to work for a scraping company and I used it all day every day - load a page with inspector open, find your request, right click copy as curl, paste into trillworks and boom you have the request you want to automate (modulo fiddling with cookies). A+ bang&#x2F;line of code
tzuryover 5 years ago
Failed for this one<p><pre><code> Curl -vLkXPOST https:&#x2F;&#x2F;www.google.com</code></pre>
评论 #21226700 未加载
empath75over 5 years ago
I feel like going the other way would be more useful.
评论 #21225203 未加载