尝试从服务器响应打印简单JSON时属性错误,类型错误,名称错误?

时间:2016-05-10 14:59:12

标签: python json python-2.7 api

我正在尝试获取JSON并打印VIA python scirpt。我得到了服务器200的响应,不知道为什么我无法打印文件。请帮我这个!!

使用的代码是:

Import Requests
response = requests.get("https://Site1/rest/settings/all-server-status", params={'serverId': '56cd7e4d2d0edcace915e674'}, verify=False)
json_data = json.loads(response.text)

我得到以下错误:

 Traceback (most recent call last):
  File "<pyshell#51>", line 1, in <module>
    json_data = json.loads(response.text)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

我也试过以下陈述,但没有回复:

json_data = json.loads(response)
json_data = json.loads(response.read())

期望的Json Sample输出是:

[{"id":"56cd7e4d2d0edcace915e674","protocol":"https","hostName":"x.x.x.x","port":443,"serverName":"Site1","status":"connected","connected":true}]

提前致谢!

1 个答案:

答案 0 :(得分:1)

您正在进行的POST请求未返回任何内容,但Test Test Test 表示连接成功(无SSL错误等)。

问题在于:Response 200

我建议您调试params={'serverId': '56cd7e4d2d0edcace915e674'}

首先检查request.get()是否有效。