aiohttp.web_exceptions.HTTPGatewayTimeout

Here are the examples of the python api aiohttp.web_exceptions.HTTPGatewayTimeout taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: home-assistant Source File: mjpeg.py
    @asyncio.coroutine
    def handle_async_mjpeg_stream(self, request):
        """Generate an HTTP MJPEG stream from the camera."""
        # aiohttp don't support DigestAuth -> Fallback
        if self._authentication == HTTP_DIGEST_AUTHENTICATION:
            yield from super().handle_async_mjpeg_stream(request)
            return

        # connect to stream
        try:
            with async_timeout.timeout(10, loop=self.hass.loop):
                stream = yield from self.hass.websession.get(
                    self._mjpeg_url,
                    auth=self._auth
                )
        except asyncio.TimeoutError:
            raise HTTPGatewayTimeout()

        response = web.StreamResponse()
        response.content_type = stream.headers.get(CONTENT_TYPE_HEADER)

        yield from response.prepare(request)

        try:
            while True:
                data = yield from stream.content.read(102400)
                if not data:
                    break
                response.write(data)
        finally:
            self.hass.async_add_job(stream.release())
            yield from response.write_eof()

Example 2

Project: home-assistant Source File: synology.py
    @asyncio.coroutine
    def handle_async_mjpeg_stream(self, request):
        """Return a MJPEG stream image response directly from the camera."""
        streaming_url = SYNO_API_URL.format(
            self._synology_url, WEBAPI_PATH, self._streaming_path)

        streaming_payload = {
            'api': STREAMING_API,
            'method': 'Stream',
            'version': '1',
            'cameraId': self._camera_id,
            'format': 'mjpeg'
        }
        try:
            with async_timeout.timeout(TIMEOUT, loop=self.hass.loop):
                stream = yield from self.hass.websession.get(
                    streaming_url,
                    payload=streaming_payload,
                    cookies={'id': self._session_id}
                )
        except asyncio.TimeoutError:
            raise HTTPGatewayTimeout()

        response = web.StreamResponse()
        response.content_type = stream.headers.get(CONTENT_TYPE_HEADER)

        yield from response.prepare(request)

        try:
            while True:
                data = yield from stream.content.read(102400)
                if not data:
                    break
                response.write(data)
        finally:
            self.hass.async_add_job(stream.release())
            yield from response.write_eof()