Files
aios/scripts/self_diagnose.py

13 lines
865 B
Python

#!/usr/bin/env python3
import urllib.request, urllib.parse, json, http.cookiejar, os
base=os.environ.get('AIOS_WEBOPS_BASE','http://127.0.0.1:18081')
cj=http.cookiejar.CookieJar(); opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
def form(path,data):
req=urllib.request.Request(base+path,data=urllib.parse.urlencode(data).encode(),headers={'Content-Type':'application/x-www-form-urlencoded'},method='POST')
return opener.open(req,timeout=10).read().decode()
def post(path,data):
req=urllib.request.Request(base+path,data=json.dumps(data).encode(),headers={'Content-Type':'application/json'},method='POST')
return json.loads(opener.open(req,timeout=10).read().decode())
form('/login',{'username':'admin','password':'bootstrap-change-me'})
print(json.dumps(post('/api/optimization/diagnose',{}),ensure_ascii=False,indent=2))