import random import requests url='http://xxx' headers={ 'Authorization':'xxx', 'Content-Type':'application/json' } data0="" for i in range(1,20): uid=str(i) score=str(round(random.uniform(0,100),1)) cls=str(random.choice([1,2,3,4,5])) data0=data0+"{'UID':'"+uid+"','SCORE':'"+score+"','CLASS':'"+cls+"班','COMPANY_NO':'111'}"+"," data0=data0[:-1] #或者是data0=data0.rstrip(',') data='''{ 'info': {'interfaceCode':'uintfc_test01', 'CS_TEST_YHJRJK':[ '''+data0+''' ]} }''' print(data) data=data.encode('utf-8') response=requests.post(url=url,headers=headers,data=data) print(response.content.decode('utf-8'))