# coding:utf-8
import requests
import os
url = 'http://替换图片上传接口'
h = {
"Host": "192.168.60.178:5007",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
"Accept-Encoding": "gzip, deflate",
"Referer": "http://192.168.60.178:5007/",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": "4448",
}
#图片路径
img_path ="./images/"
files_name = os.listdir(img_path) #得到文件夹下的所有文件名称
num = 0 #图片上传初始计数
for file in files_name:
# 参数rb,以二进制格式打开一个文件用于只读
f ={ "file": (file, open("./images/"+file, "rb"), "image/jpeg")}
r = requests.post(url, headers=h, files=f)
print(r.text)
num = num+1
print('-------------上传结束---------共上传',num,'张图片------------------')
说明: