使用以下 Python 代码可以从任何 REST API 资源获取数据。
GET 示例:
>>> request = urllib2.Request("https://zfssa:215/api/network/v1/routes")
>>> response = opener.open(request)
>>> response.getcode()
200
>>> body = json.loads(response.read())
>>> print json.dumps(body, sort_keys=True, indent=4)
{
"routes": [
{
"destination": "0.0.0.0",
"family": "IPv4",
"gateway": "10.80.231.1",
"href":
"/api/network/v1/routes/ixgbe0,0.0.0.0,10.80.231.1",
"interface": "ixgbe0",
"mask": 0,
"type": "static"
}
]
}