下面是我写的python requests OrderedDict模块应用列子

import requests
import time
import json
from collections import OrderedDict

#构造header
headers1 = {
            "Host": "st.blockcdn.org:8396",
            "Content-Type": "application/x-www-form-urlencoded",   
            "User-Agent": "Go-http-client/1.1",
             }

headers2 = {
            "Host": "st.blockcdn.org:8396",
            "Content-Type": "application/json",   
            "User-Agent": "Go-http-client/1.1",
             }
#url地址
url = "http://st.blockcdn.org:8396/iden"
url1 = "http://st.blockcdn.org:8396/add"
#OrderedDict()有序字典 json.dumps转换为json数据
form_data = OrderedDict()
form_data["Id"] = "V0k1RUZGWlg3UTcEZub2M="
data=json.dumps(form_data)

form_data1 = OrderedDict()
form_data1["Id"] = "V0k1RUZGWlg3UTcEZub2M="
form_data1["Cpuinfo"] = "TDIuMA=="
form_data1["Load"] = "MA=="
form_data1["Freemen"] = "MA=="
form_data1["Freecipan"] = "OTY1Nw=="
form_data1["Freeswap"] = "MA=="
form_data1["Idcpu"] = "MA=="
form_data1["Tvar_free"] = "MEUrMDA="
form_data1["Rvar_free"] = "MA=="
form_data1["Build_num"] = "100"
form_data1["GOOS"] = "linux"
form_data1["GOARCH"] = "amd64"
data1=json.dumps(form_data1)

form_data2 = OrderedDict()
form_data2["Id"] = "V0k1RUZGWlg3UTcEZub2M="
data2=json.dumps(form_data2)
#white 无限循环post数据  time.sleep延时秒
while(True):
    results = requests.post(url, data, headers=headers1).text
    print results

    results1 = requests.post(url1, data1, headers=headers2).text
    print results1

    results2 = requests.post(url, data2, headers=headers1).text
    print results2

    time.sleep(50)

    results3 = requests.post(url1, data1, headers=headers2).text
    print results3

    time.sleep(60)

菜鸟一枚大佬勿喷 送上美女
21.jpg

如果觉得我的文章对你有用,请随意赞赏