python post上传文件

西北逍遥 / 2023-08-31 / 原文

python post上传文件

 

import requests
import json
url = 'http://cnbim.com/upload'
file_path = 'path/1/2/file.jpg'
data = {
    'file': open(file_path, 'rb'),
    'id': 's1',
    # add other fields as needed
}
r = requests.post(url, json=data)
print(r.text)

 

 

 

########################