Python通過requests模塊處理form-data請求格式


1、安裝 requests_toolbelt 模塊,引入該模塊下的 MultipartEncoder

2、在 請求體 中使用該模塊函數,請求頭中增加對應參數值

from requests_toolbelt.multipart.encoder import MultipartEncoder
import requests


request_body = MultipartEncoder(
    {
        "language": "中文",
        "name": "大魔王",
        "age": "18",
        "height": 180,
        "weight": 180,
        "photo": ""
    }
)

request_header = {
    "Content-Type": request_body.content_type
}

response_body = requests.post(url, data=request_body, headers=request_header)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM