• 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)
    
  • 相关阅读:
    excel unixtime与北京时间互转
    vim的漫漫长征路
    const常量
    第一章:绪论
    2.4奇偶校验
    2.3数据校验的基本原理
    2.2定点与浮点数据表示
    2.1机器数及其特点
    1.2计算机系统性能评价
    冯诺依曼结构原理及层次分析
  • 原文地址:https://www.cnblogs.com/We612/p/12169927.html
Copyright © 2020-2023  润新知