Created
July 23, 2020 17:27
-
-
Save gfranxman/960457e337c141c519a31a16a562d785 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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