Created
August 28, 2018 06:38
-
-
Save kirillsulim/9d21beed4b15c27e6d32fe47745b6bf1 to your computer and use it in GitHub Desktop.
Some
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
method: POST | |
url: http://ya.ru | |
params: | |
some-param: bblabla | |
headers: | |
X-Some-Header: balbla blabla vla | |
body: > | |
{ | |
"just": "some", | |
"json": 123, | |
"object": { | |
"inner": null | |
} | |
} |
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
#!/usr/bin/env python3 | |
import requests | |
import sys | |
import yaml | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-s', action='store_true') | |
parser.add_argument('file', metavar='FILE', type=argparse.FileType('r')) | |
class App: | |
def run(self, args): | |
self.args = parser.parse_args(args[1:]) | |
with(self.args.file) as f: | |
try: | |
reqdata = yaml.load(f) | |
#print(reqdata) | |
self.run_req(reqdata) | |
except Exception as e: | |
print(e) | |
raise | |
#print(args) | |
def run_req(self, reqdata): | |
response = requests.request(str(reqdata['method']).lower(), reqdata['url'], params=reqdata['params'], headers=reqdata['headers'], data=reqdata['body']) | |
if self.args.s: | |
print(response.status_code) | |
#print(response.text) | |
if __name__ == '__main__': | |
App().run(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment