Beispiel #1
0
    async def get(self, address, params, headers):
        with aio_timeout(self.operation_timeout):
            response = await self.session.get(address,
                                              params=params,
                                              headers=headers)

            return await self.new_response(response)
Beispiel #2
0
 async def post(self, address, message, headers):
     self.logger.debug("HTTP Post to %s:\n%s", address, message)
     with aio_timeout(self.operation_timeout):
         response = await self.session.post(address,
                                            data=message,
                                            headers=headers)
         self.logger.debug("HTTP Response from %s (status: %d):\n%s",
                           address, response.status, await response.read())
         return response
Beispiel #3
0
 async def post(self, address, message, headers):
     self.logger.debug("HTTP Post to %s:\n%s", address, message)
     with aio_timeout(self.operation_timeout):
         response = await self.session.post(
             address, data=message, headers=headers)
         self.logger.debug(
             "HTTP Response from %s (status: %d):\n%s",
             address, response.status, await response.read())
         return response
Beispiel #4
0
    async def get(self, address, params, headers):
        with aio_timeout(self.operation_timeout):
            response = await self.session.get(
                address,
                params=params,
                headers=headers,
                verify_ssl=self.verify_ssl,
                proxy=self.proxy,
            )

            return await self.new_response(response)
Beispiel #5
0
 async def _load_remote_data_async():
     nonlocal result
     with aio_timeout(self.load_timeout):
         response = await self.session.get(url)
         result = await response.read()
         try:
             response.raise_for_status()
         except aiohttp.ClientError as exc:
             raise TransportError(message=str(exc),
                                  status_code=response.status,
                                  content=result).with_traceback(
                                      exc.__traceback__) from exc
Beispiel #6
0
 async def _load_remote_data_async():
     nonlocal result
     with aio_timeout(self.load_timeout):
         response = await self.session.get(url)
         result = await response.read()
         try:
             response.raise_for_status()
         except aiohttp.ClientError as exc:
             raise TransportError(
                 message=str(exc),
                 status_code=response.status,
                 content=result
             ).with_traceback(exc.__traceback__) from exc
    async def fetch(self, url, use_json=False):
        async with get_session() as session:
            async with aio_timeout(10):
                async with session.get(url) as response:
                    status_type = response.status // 100
                    if use_json:
                        data = await response.json()
                    else:
                        data = await response.text()
        print(url)

        if status_type == 4:
            raise Fetch400Error("404 Not found")
        elif status_type == 5:
            raise Fetch500Error("500 Server error")
        elif status_type != 2:
            raise UnknownNon200Error("Non 200 - Unknown")

        return data
Beispiel #8
0
    async def timed_future_completion(
        task_or_future: Union[Task, Future],
        timeout: Union[int, float] = 10,
        cancel: bool = False,
        loop: Optional[AbstractEventLoop] = None,
    ) -> None:
        """Waits for the supplied task/future to resolve until the timeout time has been reached.
        If cancel is true the supplied task/future is cancelled then awaited.

        :param task_or_future: The task/future to be awaited
        :param timeout: The maximum amount of time the wait will be. Defaults to 10 seconds
        :param cancel: Should the task/future be canceled before awaiting completing. Defaults to False
        :param loop: Optional reference to the automation's event loop.
        """
        _loop = Helper.ensure_loop(loop)
        if cancel and not task_or_future.done():
            task_or_future.cancel()
        try:
            async with aio_timeout(timeout, loop=_loop):
                await task_or_future
        except (CancelledError, TimeoutError):
            pass
        except Exception:
            raise
Beispiel #9
0
 async def cancel(self, con, timeout=None):
     if timeout:
         async with aio_timeout(timeout) as cm:
             await con.cancel()
     else:
         await con.cancel()
Beispiel #10
0
    async def get(self, address, params, headers):
        with aio_timeout(self.operation_timeout):
            response = await self.session.get(
                address, params=params, headers=headers)

            return await self.new_response(response)