Skip to content

Instantly share code, notes, and snippets.

@groveriffic
Created October 1, 2018 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groveriffic/ce075d3880f2e584ef26cc66b25f94a1 to your computer and use it in GitHub Desktop.
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
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