Created
October 1, 2018 16:26
-
-
Save groveriffic/ce075d3880f2e584ef26cc66b25f94a1 to your computer and use it in GitHub Desktop.
Prints out a command line curl from the same inputs your would have used with requests
This file contains 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 curl_syntax(url, params=[], headers=[]): | |
print(url, params, headers) | |
from urllib.parse import urlencode | |
print('curl \\') | |
print(' --verbose \\') | |
for k in sorted(headers.keys()): | |
v = headers[k] | |
print(' --header "{}: {}" \\'.format(k, v)) | |
params_array = [] | |
for k in sorted(params.keys()): | |
v = params[k] | |
params_array.append((k, v)) | |
if params_array: | |
url += "?" + urlencode(params_array) | |
print(' "{}"'.format(url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment