Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- # 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