Python中JSON数据的问题

2024-04-26 23:55:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个项目,将Verizon thingspacerestapi合并到Python程序中。在

一位同事给我提供了一个CURL的例子,这个例子很有用(我不熟悉CURL,所以正在尝试转换成Python)。在

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "VZ-M2M-Token: 621d9779-f8bc-4fe9-91dd-b726c52e7117" --header "Authorization: Bearer 89ba225e1438e95bd05c3cc288d3591" -d "{\"accountName\": \"TestAccount-1\"}" https://thingspace.verizon.com/api/m2m/v1/devices/actions/list

我正试图将这个完全相同的请求转换成一个Python函数。以下是我所拥有的:

^{pr2}$

当我运行这个程序时,我得到以下JSON错误消息:

(400, 'Bad Request', u'{"errorCode":"REQUEST_FAILED.UnexpectedError","errorMessage":"Could not read document: Unrecognized token \'accountName\': was expecting (\'true\', \'false\' or \'null\')\n at [Source: java.io.PushbackInputStream@51ceaf1d; line: 1, column: 13]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token \'accountName\': was expecting (\'true\', \'false\' or \'null\')\n at [Source: java.io.PushbackInputStream@51ceaf1d; line: 1, column: 13]"}')

您可以在此处引用API信息:https://thingspace.verizon.com/developer/apis#/Connectivity%20Management/API%20Reference/Retrieve%20Device%20Information.html

我相信我的JSON字符串可能有问题,但我需要另一副眼睛。在


Tags: https程序comtokenjsonapplicationcurl例子