抓到的请求如下图:请求包含了文件及键值对

python:post接口、发送multipart/form-data格式请求

# -*- coding: utf-8 -*-
import os
import requests
import time

dirpath = r"D:\***"
filenames = os.listdir(dirpath)

jg = r'D:\***.txt'
fi = open(jg, 'w')
for filename in filenames:
    portion = os.path.splitext(filename)  # 将文件名和缀名分成俩部分
    if portion[1] == '.jpg' or portion[1] == '.png':
        filepath = os.path.join(dirpath, filename)

        # 接口
        url = 'https://***/***'
        files={'topn':(None,'2'),'image_file':('file',open(filepath,'rb'),'image/jpeg')}
        r = requests.post(url,files=files)
        resp = r.json()
        print(resp)

        fi.write(str(filename) + ':' + str(resp) + '\n')
fi.close()
files={'topn':(None,'2'),'image_file':('file',open(filepath,'rb'),'image/jpeg')}中的键对应抓包的form Data中name对应的值

相关文章:

  • 2022-01-18
  • 2021-12-31
  • 2021-08-31
  • 2021-08-31
  • 2021-10-19
  • 2021-09-18
  • 2021-11-01
  • 2021-07-20
猜你喜欢
  • 2017-12-03
  • 2021-09-10
  • 2021-11-17
  • 2018-11-26
  • 2021-09-19
  • 2021-10-13
相关资源
相似解决方案