아래와 같이 코드 실행시 다음과 같이 JSON data를 가져올 수 있다.
import requests
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
import json
auth = HTTPBasicAuth(username='1004lucifer', password='1234qwer')
webLogicUrl = 'http://192.168.43.51:7001'
serverUrl = 'http://192.168.43.51:7001/management/tenant-monitoring/servers/AdminServer'
clusterUrl = 'http://192.168.43.51:7001/management/tenant-monitoring/clusters/Cluster-0'
def __headers():
return {'Accept': 'application/json'}
def webLogicAPI(url, userAuth):
serverRequest = requests.get(url=url, headers=__headers(), auth=userAuth)
data = serverRequest.json()
jsonData = json.dumps(data)
return jsonData
serverMonitoring = webLogicAPI(serverUrl, auth)
clusterMonitoring = webLogicAPI(clusterUrl, auth)
print("serverMonitoring : ", serverMonitoring)
print("clusterMonitoring : ", clusterMonitoring)