Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import time
- gets = [
- {
- "name": "Get chain",
- "url": "http://127.0.0.1/get_chain",
- "params": []
- },
- ]
- while True:
- for g in gets:
- r = get(g['url'], g['params'])
- if r.status_code == 200:
- r = r.json()
- print(str(g['name']) + ' 200')
- print(r)
- print('')
- else:
- print(str(g['name']) + ' ' + r.status_code)
- time.sleep(1)
- # To access values from these functions:
- # r.json() returns JSON response from request
- # r.status_code gives you the http code from the response
- #
- # For params, pass an array of dictionaries
- # e.g.
- # [ { "name": "name", "value": "value" } ]
- #
- def get(url, params):
- if len(params) > 0:
- url += '?'
- for param in params:
- url = url + str(param['name']) + '=' + str(param['value'])
- headers = {
- 'accept': 'application/json',
- }
- r = requests.get(url, headers=headers)
- return r
- #
- # For params, pass the data you want to send in the POSt request
- # e.g.
- # [ { "name": "value", "name2": "value2" } ]
- #
- def post(url, params):
- headers = {
- 'accept': 'application/json',
- }
- r = requests.post(url, data=params, headers=headers)
- return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement