def _openURL2(self,str_URLsuffix):
str_responseData = None
url = None
try:
url = self._url + str_URLsuffix
password_mgr = urlconnection.HTTPPasswordMgr()
password_mgr.add_password(None, url, self._userName, self._userPass)
auth_handler = urlconnection.HTTPBasicAuthHandler(password_mgr)
proxy = urlconnection.ProxyHandler({}) # Uses NO Proxy
opener = urlconnection.build_opener(proxy, auth_handler)
urlconnection.install_opener(opener)
response = urlconnection.urlopen(url, timeout = 5)
if response.getcode() == 200:
byte_responseData = response.read()
str_responseData = byte_responseData.decode('UTF-8')
else:
self.dictEsPluginData['status'] = '0'
self.dictEsPluginData['msg'] = 'Invalid response after opening URL : ' + str(response.getcode())
except HTTPError as e:
self.dictEsPluginData['status'] = '0'
self.dictEsPluginData['msg'] ='HTTP Error '+str(e.code)
except URLError as e:
self.dictEsPluginData['status'] = '0'
self.dictEsPluginData['msg'] = 'URL Error '+str(e.reason)
except InvalidURL as e:
self.dictEsPluginData['status'] = '0'
self.dictEsPluginData['msg'] = 'Invalid URL'
except Exception as e:
self.dictEsPluginData['status'] = '0'
self.dictEsPluginData['msg'] = 'Exception while opening stats url in python 2 : ' + str(e)
finally:
return str_responseData
评论列表
文章目录