Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import requests
  2.  
  3. # To access values from these functions:
  4. # r.json() returns JSON response from request
  5. # r.status_code gives you the http code from the response
  6.  
  7. #
  8. # For params, pass an array of dictionaries
  9. # e.g.
  10. # [ { "name": "name", "value": "value" } ]
  11. #
  12. def get(url, params):
  13.     if len(params) > 0:
  14.         url += '?'
  15.         for param in params:
  16.             url = url + str(param['name']) + '=' + str(param['value'])
  17.  
  18.     headers = {
  19.         'accept': 'application/json',
  20.     }
  21.  
  22.     r = requests.get(url, headers=headers)
  23.  
  24.     return r
  25.  
  26. #
  27. # For params, pass the data you want to send in the POSt request
  28. # e.g.
  29. # [ { "name": "value", "name2": "value2" } ]
  30. #
  31. def post(url, params):
  32.  
  33.     headers = {
  34.         'accept': 'application/json',
  35.     }
  36.  
  37.     r = requests.post(url, data=params, headers=headers)
  38.  
  39.     return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement