1. requests_toolbelt
先安装requests_toolbelt
pip install requests_toolbelt
上传实例
import requests
from requests_toolbelt import MultipartEncoder
upload_url = 'https://your/upload/url'
payload = {
'file': ('test.jpg', open('test.jpg', 'rb'), 'image/jpeg')
}
m = MultipartEncoder(payload)
headers = {
'Content-Type': m.content_type,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
}
res = requests.post(url, headers=headers, data=m, verify=False)
print(res.json())
标签:headers,python,toolbelt,url,MultipartEncoder,requests,上传
From: https://www.cnblogs.com/wstong2052/p/17863968.html