Пример #1
0
 async def _get_response(self, full_url, headers, timeout):
     try:
         timeout = aiohttp.ClientTimeout(total=self.TIMEOUT_SECONDS)
         async with self._session(timeout=timeout) as session:
             async with session.get(full_url, headers=headers) as resp:
                 if resp.status != 200:
                     text = await resp.text()
                     raise MetadataRetrievalError(
                         error_msg=(
                                       "Received non 200 response (%d) "
                                       "from ECS metadata: %s"
                                   ) % (resp.status, text))
                 try:
                     return await resp.json()
                 except ValueError:
                     text = await resp.text()
                     error_msg = (
                         "Unable to parse JSON returned from ECS metadata services"
                     )
                     logger.debug('%s:%s', error_msg, text)
                     raise MetadataRetrievalError(error_msg=error_msg)
     except RETRYABLE_HTTP_ERRORS as e:
         error_msg = ("Received error when attempting to retrieve "
                      "ECS metadata: %s" % e)
         raise MetadataRetrievalError(error_msg=error_msg)
Пример #2
0
 def _get_response(self, full_url, headers, timeout):
     try:
         response = self._session.get(full_url, headers=headers,
                                      timeout=timeout)
         if response.status_code != 200:
             raise MetadataRetrievalError(
                 error_msg="Received non 200 response (%s) from ECS metadata: %s"
                 % (response.status_code, response.text))
         try:
             return json.loads(response.text)
         except ValueError:
             raise MetadataRetrievalError(
                 error_msg=("Unable to parse JSON returned from "
                            "ECS metadata: %s" % response.text))
     except RETRYABLE_HTTP_ERRORS as e:
         error_msg = ("Received error when attempting to retrieve "
                      "ECS metadata: %s" % e)
         raise MetadataRetrievalError(error_msg=error_msg)
Пример #3
0
 def _get_response(self, full_url, headers, timeout):
     try:
         AWSRequest = botocore.awsrequest.AWSRequest
         request = AWSRequest(method='GET', url=full_url, headers=headers)
         response = self._session.send(request.prepare())
         response_text = response.content.decode('utf-8')
         if response.status_code != 200:
             raise MetadataRetrievalError(
                 error_msg=
                 "Received non 200 response (%s) from ECS metadata: %s" %
                 (response.status_code, response_text))
         try:
             return json.loads(response_text)
         except ValueError:
             raise MetadataRetrievalError(
                 error_msg=("Unable to parse JSON returned from "
                            "ECS metadata: %s" % response_text))
     except RETRYABLE_HTTP_ERRORS as e:
         error_msg = ("Received error when attempting to retrieve "
                      "ECS metadata: %s" % e)
         raise MetadataRetrievalError(error_msg=error_msg)