Skip to content

Instantly share code, notes, and snippets.

@gfranxman
Created July 23, 2020 17:27
Show Gist options
  • Save gfranxman/960457e337c141c519a31a16a562d785 to your computer and use it in GitHub Desktop.
Save gfranxman/960457e337c141c519a31a16a562d785 to your computer and use it in GitHub Desktop.
def request_as_curl(request):
"""
construct a curl command from a (failed) request.
"""
url = request.url
headers = request.headers
data = request.body.decode("utf-8")
method = request.method
command = "curl -v -H {headers} {data} -X {method} {uri}"
data = f" -d '{data}'"
header_list = ['"{0}: {1}"'.format(k, v) for k, v in headers.items()]
header = " -H ".join(header_list)
return command.format(method=method, headers=header, data=data, uri=url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment