[b]"How can I convert Python code to curl for API requests?"[/b] or [b]"What's the best way to convert Python code

16 Replies, 904 Views

Not a tool, but a hack:

If your Python code uses `requests`, print `response.request` and manually map it to curl.

Example:
```python
r = requests.get(url, headers=headers)
print(r.request.method, r.request.url, r.request.headers, r.request.body)
```

Then build the curl from those parts. Tedious, but no extra deps.

For quick one-offs, this works. For heavy use, though, tools like `curlify` are worth it.

Messages In This Thread



Users browsing this thread: 1 Guest(s)