The request content was malformed: Unrecognized token 'contentType': was expecting ('true', 'false' or 'null')

报错日志:

The request content was malformed:
Unrecognized token 'contentType': was expecting ('true', 'false' or 'null')

1、执行post请求:req = requests.post(url_post, headers=headers, cookies=cookies, data=data, verify=False)
2、出现上述“报错日志”
3、解决方法:
这是因为在调用时输入的参数格式不对(使用Fiddler察看请求参数的格式,要求为json格式,默认是application格式)!把请求语句修改为:
req = requests.post(url_post, headers=headers, cookies=cookies, data=json.dumps(data), verify=False)

4、下面是执行失败的代码块

url_post = 'http://Ip:1065/api/itoa/splquery/common'
        data = {
            "content": "start=now-168h | metric=FILESYSTEM.FSCapacity ip="144.240.208.87_145.240.208.87" instance="/ORONLAPS" | stats max by 30m,ip,instance",
            "contentType": "text", "uriPath": "/rest/metric/_q", "httpMethod": "post"}
        # data = json.dumps(data)
        # 下面是错误代码
        req = requests.post(url_post, headers=headers, cookies=cookies, data=data, verify=False)
        # 正确代码
        # req = requests.post(url_post, headers=headers, cookies=cookies, data=json.dumps(data), verify=False)
        # res = req.text
        # print(res)
        print(req.status_code)
原文地址:https://www.cnblogs.com/We612/p/12169927.html