0

I write this code import requests

auth_token='eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZX$
hed = {'Authorization': 'Bearer ' + auth_token}
data = {'app' : 'aaaaa'}

url =  'https://203.0.113.106:6443/api'
a=response = requests.get(url, headers=hed,verify=False)
print(a.json())

It receives

{u'serverAddressByClientCIDRs': [{u'clientCIDR': u'0.0.0.0/0', u'serverAddress': u'203.0.113.106:6443'}], u'kind': u'APIVersions', u'versions': [u'v1']}

But I want to print it like

{
  "kind": "APIVersions",
  "versions": [
    "v1"
  ],
  "serverAddressByClientCIDRs": [
    {
      "clientCIDR": "0.0.0.0/0",
      "serverAddress": "203.0.113.106:6443"
    }
  ]

What should i do?

check nova
  • 271
  • 1
  • 2
  • 11

1 Answers1

1

You can re-encode the JSON with the standard json module:

import json

data = response.json()
print(json.dumps(data, indent=2))
Norrius
  • 7,558
  • 5
  • 40
  • 49