Advertisement
furas

Python - Requests JSON

Jul 13th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #
  2. # converting from CURL to REQUESTS: https://curl.trillworks.com/
  3. #
  4.  
  5. import requests
  6. import datetime
  7. import pprint # pretty print
  8.  
  9. #dt = datetime.datetime(2018, 6, 29, 6, 47, 40)
  10.  
  11. dt = datetime.datetime.now()
  12.  
  13. td_7mins = datetime.timedelta(minutes=7)
  14.  
  15. dt = dt - td_7mins # now - 7 minutes
  16.  
  17. #timestamp = "@timestamp:[{}.000Z TO *]".format(now.strftime("%Y-%m-%dT%H:%M:%S"))
  18. timestamp = dt.strftime("@timestamp:[%Y-%m-%dT%H:%M:%S.000Z TO *]")
  19.  
  20. data = {
  21.     "query": {
  22.         "query_string": {
  23.             "query": timestamp
  24.         }
  25.       },
  26.     "size": 1000
  27. }
  28. print(data)
  29.  
  30. url = "https://httpbin.org/get" # good for tests
  31.  
  32. r = requests.get(url, json=data, headers=headers, verify=False, auth=('u_name', 'XXX'))
  33.  
  34. pprint.pprint(r.json())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement