Skip to content

Instantly share code, notes, and snippets.

@kbaesler
Created June 1, 2017 01:03
Show Gist options
  • Save kbaesler/a622866ff61dbd2d81cf1b41bf5e5fb2 to your computer and use it in GitHub Desktop.
Save kbaesler/a622866ff61dbd2d81cf1b41bf5e5fb2 to your computer and use it in GitHub Desktop.
A python script that will send a REST request to the URL provided at the command line.
import sys
import requests
def main(url, **kwargs):
try:
print ('GET: {0}'.format(url))
print ('PARAMS:')
for k,v in kwargs.items():
print ('\t{0} = {1}'.format(k,v))
response = requests.get(url, params=kwargs.items())
if response.ok:
print ('STATUS: {0}'.format(response.status_code))
else:
response.raise_for_status()
return 0
except Exception as ex:
return -1
if __name__ == "__main__":
sys.exit(main(sys.argv[1],
**dict(arg.split('=') for arg in sys.argv[2:]))) # kwargs
# Usage:
# python send-request.py http://localhost:8733/jtx/dnvgl/etl/api/import id=2205
# GET: http://localhost:8733/jtx/dnvgl/etl/api/import
# PARAMS:
# id = 2205
# STATUS: 202
# python send-request.py http://localhost:8733/jtx/dnvgl/etl/api/export version=JOB_2205
# GET: http://localhost:8733/jtx/dnvgl/etl/api/export
# PARAMS:
# version = JOB_2205
# STATUS: 202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment