需要引入 python3 requests模块:
pip3 install requests
import requests
from requests.packages.urllib3.filepost import encode_multipart_formdata
def post_files(url,header,data,filename,filepath):
data['file']= (filename,open(filepath,'rb').read())
encode_data = encode_multipart_formdata(data)
data = encode_data[0]
header['Content-Type'] = encode_data[1]
r = requests.post(url, headers=header, data=data)
print(r.text)
if __name__=="__main__":
post_files('http://abc.ttt.cn/api/upload/file/v2', {}, {}, "1.png", 'C:\\Users\\qing\\Desktop\\1.png')
网友评论