requests.post发送字典套字典

import requests
import json
a = {
        "data": {
            "project": {
                "url": "https: //www.teambition.com/project/596823f91f2d170ed3287f29/home",
                "_organizationId": "59682393361ddc461fa0f252",
                "_id": "596823f91f2d170ed3287f29",
                "name": "Issue管理"
            },
            "task": {
                "content": "FSA10001测试",
                "executor": {
                    "_id": "596829cfe525d47670c4e479",
                    "name": "冯超群",
                    "avatarUrl": "https: //striker.teambition.net/thumbnail/110ud2216b9615c796999e437606a63f8033/w/200/h/200"
                },
                "_id": "5971cf438900c23e17cd3fcb"
            },
            "user": {
                "_id": "59682392e525d47670c4d49a",
                "name": "高飞",
                "avatarUrl": "https: //striker.teambition.net/thumbnail/110u54004f5d5582fc2e6eb7a08541f1573a/w/200/h/200"
            }
        },
        "event": "task.remove"
    }
#方式一
# headers = {"Content-Type":"application/json"}
# requests.post(url='http://127.0.0.1:8000/api/index.html',headers=headers,data=json.dumps(a))
#方式二
# requests.post(url='http://127.0.0.1:8000/api/index.html',json=a) #只有body里面有

#下面的请不要看------------------------------------------------------------------------------------------------
#经典错误方式
# headers = {"Content-Type":"application/x-www-form-urlencoded"}
# requests.post(url='http://127.0.0.1:8000/api/index.html',headers = headers,data=a) #post和body里面都只有字典的key
#SB错误方式一
# headers = {"Content-Type":"application/x-www-form-urlencoded"}
# requests.post(url='http://127.0.0.1:8000/api/index.html',headers = headers,json=a)
#SB错误方式二
# headers = {"Content-Type":"application/x-www-form-urlencoded,application/json"}
# requests.post(url='http://127.0.0.1:8000/api/index.html',headers = headers,data=a)

  

posted @ 2017-08-08 19:33  黄土地上的黑石头  阅读(330)  评论(0编辑  收藏  举报