我正在编写一个脚本来发送带有一些从 JSON 文件加载的数据的帖子请求。JSON:[ { "title": "Mr", "firstname": "Joe", "lastname": "Blogs", "phonenumber": 7901893333 }, { "title": "Miss", "firstname": "Jane", "lastname": "Wang", "phonenumber": 7901894444 }, { "title": "Mrs", "firstname": "Rosie", "lastname": "Thomas", "phonenumber": 7901895555 }]代码:import requestsimport jsonimport threadingwith open('data.json', encoding='utf-8') as data_file: data = json.loads(data_file.read())def send_info(): url = 'http://ptsv2.com/t/e092q-1537974317/post' payload = { 'titleCode': data[0]["title"], 'firstName': data[0]["firstname"], 'lastName': data[0]["lastname"], 'cellPhone': data[0]["phonenumber"] } r = requests.post(url, params=payload) print(r.text)threads = []for i in range(len(data)): t = threading.Thread(target=send_info) threads.append(t) t.start()目前所有线程都只使用'data[0]'。如何让一个线程使用“data[0]”,下一个使用“data[1]”,下一个使用“data[2]”?
添加回答
举报
0/150
提交
取消