request.put(),其余api在请求正文中发送json时引发错误的请求错误

时间:2018-11-03 13:00:25

标签: python-3.x rest spring-boot python-requests

嗨,我是python的新手,下面是我的调用REST api的代码:

    api_url = 'https://gateway.eu1-int.myproject.io/api/iottimeseries/v3/timeseries/1234/propertyname'
    payload =[{
       "_time": "2017-12-30T09:54:28.502Z",
       "FLWheel_qc": 1,
       "FRWheel_qc": 13,
       "RLWheel_qc": 55,
       "RRWheel_qc": 6
    }]
    headers = {'Content-Type': 'application/json'}
    http_proxy = 'http://' + rest_client_config.proxy_host + ':' + rest_client_config.proxy_port
    proxy_dict = {
        "https": http_proxy
    }
    json_payload = json.dumps(payload)
    r = requests.put(api_url, json=payload, headers=headers, proxies=proxy_dict)
    json_data = json.loads(r.text)

我在request.put中尝试了不同的组合

    json_payload = json.dumps(payload)
    r = requests.put(api_url, data=json_payload, headers=headers, proxies=proxy_dict)

或:

r = requests.put(api_url, data=payload, headers=headers, proxies=proxy_dict)

rest api是使用spring boot开发的,出现以下错误:

{'timestamp': '2018-11-03T12:36:09.585+0000', 'status': 400, 'error': 'Bad Request', 'exception': 'org.springframework.http.converter.HttpMessageNotReadableException', 'message': 'JSON parse error: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token\n at [Source: java.io.PushbackInputStream@664d6d8c; line: 1, column: 1]', 'path': 'api/iottimeseries/v3/timeseries/1234/propertyname'}

很久以来我一直坚持这一点。我已经尝试了所有可能的解决方案。但是邮递员的要求完全相同。如果我有任何遗漏,请告诉我。

0 个答案:

没有答案