您好,登錄后才能下訂單哦!
# coding=utf-8
import requests, json
import hashlib, time
import base64
from locust import HttpLocust,TaskSet,task
IP_server = "192.168.1.25"
def md5_int(vale):
md5_int = vale
str_md5 = hashlib.md5(md5_int.encode()).hexdigest()
return str_md5
def getsession():
url = "https://{}/login".format(IP_server)
token = {}
data = json.dumps({
"name": "admin",
"password": md5_int('123456'),
})
url = requests.post(url=url, data=data)
token["session_id"] = url.json()["session_id"]
token["cluster_id"] = token["session_id"].split('@')[1]
return token
token = getsession()
class MyBlogs(TaskSet):
data = json.dumps({
"cameid": "3",
"limit": 20,
})
@task(1)
def post_test(self):
# 定義請求
with self.client.post("/cick/weibocke/", headers=token, data=self.data, catch_response=True) as response:
if response.status_code == 200:
print("success")
else:
print("fails")
class websitUser(HttpLocust):
task_set = MyBlogs
min_wait = 3000 # 單位為毫秒
max_wait = 6000 # 單位為毫秒
if __name__ == "__main__":
import os
os.system("locust -f test.py ")
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。