def getData(self):
try:
### Create Authentication Handler for the HTTP Request
pwdmgr = urllib2.HTTPPasswordMgr()
pwdmgr.add_password(None, self.url, USERNAME, PASSWORD)
auth = urllib2.HTTPBasicAuthHandler(pwdmgr)
### Create Proxy Handler for the HTTP Request
proxy = urllib2.ProxyHandler({}) # Uses NO Proxy
### Create a HTTP Request with the authentication and proxy handlers
opener = urllib2.build_opener(proxy, auth)
urllib2.install_opener(opener)
### Get HTTP Response
response = urllib2.urlopen(self.url, timeout=10)
### Parse the response data
if response.getcode() == 200:
bytedata = response.read()
output = bytedata.decode('UTF-8')
self.data = self.parseData(output)
self.data['units'] = UNITS
else:
self.data['msg'] = str(response.getcode())
except Exception as e:
self.data['msg'] = str(e)
return self.data
### Parse Lighttp Server Stats Data
评论列表
文章目录