python requests方法post请求json格式处理

方法如下:

import requests
import json

data = {
    'a': 123,
    'b': 456
}

## headers中添加上content-type这个参数,指定为json格式
headers = {'Content-Type': 'application/json'}

## post的时候,将data字典形式的参数用json包转换成json格式。
response = requests.post(url='url', headers=headers, data=json.dumps(data))

posted @ 2019-10-30 12:03  Golover  阅读(8877)  评论(1编辑  收藏  举报