#-*-coding:utf-8 -*- import os,sys import requests def get_imgs(task_id): data = [] root = os.path.dirname(os.path.abspath(__file__)) filelist = os.listdir(".") filelist.sort() for file in filelist: if file.endswith(".jpg") or file.endswith(".png"): newfile = "{}_{}".format(task_id,file.split("_")[1]) os.rename(file,newfile) filelist = os.listdir(".") filelist.sort() for name in filelist: if name.endswith(".jpg") or name.endswith(".png"): data.append(os.path.join(root,name)) return data def producer(task_id): #url = "http://47.108.130.28:8000/v1/common/uppapers" url = "http://192.168.117.131:8000/v1/common/uppapers" imgs = get_imgs(task_id) for img in imgs: name = os.path.split(img)[-1] files = {"datafile":(name,open(img,"rb"))} res = requests.post(url,files=files) print(res.json()) if __name__ == "__main__": task_id = raw_input(u"please input task_id...\n") producer(task_id)