예제 #1
0
 def request_call(self, url):
     """Call web API request."""
     uri = 'http://' + self._host + ":" + str(self._port) + url
     _LOGGER.debug("Enigma: [request_call] - Call request %s ", uri)
     try:
         return self._opener.open(uri, timeout=10).read().decode('UTF8')
     except (HTTPError, URLError, ConnectionRefusedError):
         _LOGGER.exception("Enigma: [request_call] - Error connecting to \
                           remote enigma %s: %s ", self._host,
                           HTTPError.code)
         return False
예제 #2
0
 async def request_call(self, url):
     """Call web API request."""
     uri = 'http://' + self._host + ":" + str(self._port) + url
     _LOGGER.debug("Enigma: [request_call] - Call request %s ", uri)
     try:
         # Check if is password enabled
         if self._password is not None:
             # Handle HTTP Auth
             async with self._opener.get(uri,
                                         auth=aiohttp.BasicAuth(
                                             self._username,
                                             self._password)) as resp:
                 text = await resp.read()
                 return text
         else:
             async with self._opener.get(uri) as resp:
                 text = await resp.read()
                 return text
     except:
         _LOGGER.exception("Enigma: [request_call] - Error connecting to \
                           remote enigma")