POST-GET.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/python3
  2. # --*-- coding:utf-8 --*--
  3. import requests, json, os, time
  4. import pymysql
  5. import sys
  6. import time, datetime
  7. import logging
  8. Ids = []
  9. logging.basicConfig(filename='./app_time.log', level=logging.INFO)
  10. def auth_post():
  11. url_auth = "http://localhost:8000/auth"
  12. auth_body = {"username": "123", "password": "123"}
  13. auth_headers = {
  14. "Content-Type": "application/json, charset=UTF-8"
  15. }
  16. auth_original = requests.request('post', url_auth, json=auth_body, headers=auth_headers)
  17. access_token_original = auth_original.json()
  18. access_token = access_token_original['access_token']
  19. return access_token
  20. def post_x-www-form():
  21. init_headers = {'content-type': 'application/x-www-form-urlencoded'}
  22. init_url = "http://192.1.1.1:8080/init"
  23. params = {"account_ids":Ids[0]}
  24. resp = requests.post(init_url, data=params, headers=init_headers)
  25. print(resp.text)
  26. def clear_post():
  27. url_clear = "http://localhost:8000/api/range"
  28. data_headers = {
  29. 'Content-Type': 'application/json',
  30. 'Authorization': 'Bearer ' + auth_post()}
  31. json_id = {'ID': Ids}
  32. data_original = requests.post(url_clear, json=json_id, headers=data_headers)
  33. # 发送GET请求,参数为10000,带上验证信息(Auth)。
  34. def get_resource():
  35. url_clear = "http://localhost:8000/api/source/10000?region=cn-northwest-1"
  36. data_headers = {
  37. 'Content-Type': 'application/json',
  38. 'Authorization': 'Bearer ' + auth_post()}
  39. json_id = {'ID': Ids}
  40. data_original = requests.get(url_clear, headers=data_headers)