python 發送form-data表單類型的數據

在這裏插入圖片描述

from urllib3 import encode_multipart_formdata
header = {"Content-Type" : "multipart/form-data"}
data = {
“key”:"value"
}
filename = '文件名'
filepath = '文件路徑'
#在data中增加文件key/value
data['appFile']= (filename,open(filepath,'rb').read())
#轉換data數據的類型
encode_data = encode_multipart_formdata(data)
data = encode_data[0]
header['Content-Type'] = encode_data[1]
res = requests.post(url=url, headers=header, data=data)
print(res)
print(res.text)
print(res.content.decode('utf-8'))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章