0

I am trying to get JSON and print VIA python scirpt. I got response from server 200, not sure why i can not able print the file. Please help me on this!!

The Code used is:

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

I got below error:

 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

I tried below statements also but no response:

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

The Json Sample output expecting is:

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

Thanks in advance!

9
  • Could you ensure that the server is in fact returning valid json? try printing the response and running it through a JSON validator: jsonlint.com Commented May 10, 2016 at 15:03
  • Yes it is!! Valid Json. Commented May 10, 2016 at 15:04
  • you may need to use : response.json() Commented May 10, 2016 at 15:06
  • Sorry I got this error ValueError: No JSON object could be decoded Commented May 10, 2016 at 15:09
  • Folks, Any comment on this! Commented May 10, 2016 at 15:21

1 Answer 1

1

The POST request you are making is not returning anything, however the Response 200 indicates the connection was successful(No SSL error etc).

The problem is here: params={'serverId': '56cd7e4d2d0edcace915e674'}.

I would suggest debugging your request.get().

Start by checking if the https://hostname.com/key=value is valid.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.