| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/usr/bin/python3
- # --*-- coding:utf-8 --*--
- import requests, json, os, time
- import pymysql
- import sys
- import time, datetime
- import logging
- Ids = []
- logging.basicConfig(filename='./app_time.log', level=logging.INFO)
- def auth_post():
- url_auth = "http://localhost:8000/auth"
- auth_body = {"username": "123", "password": "123"}
- auth_headers = {
- "Content-Type": "application/json, charset=UTF-8"
- }
- #json为dict时,如果不指定content-type,默认为application/json
- #json为str时,如果不指定content-type,默认为application/json
- auth_original = requests.request('post', url_auth, json=auth_body, headers=auth_headers)
- access_token_original = auth_original.json()
- access_token = access_token_original['access_token']
- return access_token
- def post_x-www-form():
- init_headers = {'content-type': 'application/x-www-form-urlencoded'}
- init_url = "http://192.1.1.1:8080/init"
- params = {"account_ids":Ids[0]}
- #data为dict时,如果不指定content-type,默认为application/x-www-form-urlencoded,相当于普通form表单提交的形式
- #data为str时,如果不指定content-type,默认为text/plain
- resp = requests.post(init_url, data=params, headers=init_headers)
- print(resp.text)
- def clear_post():
- url_clear = "http://localhost:8000/api/range"
- data_headers = {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + auth_post()}
- json_id = {'ID': Ids}
- data_original = requests.post(url_clear, json=json_id, headers=data_headers)
- # 发送GET请求,参数为10000,带上验证信息(Auth)。
- def get_resource():
- url_clear = "http://localhost:8000/api/source/10000?region=cn-northwest-1"
- data_headers = {
- 'Content-Type': 'application/json',
- 'Authorization': 'Bearer ' + auth_post()}
- json_id = {'ID': Ids}
- data_original = requests.get(url_clear, headers=data_headers)
|