app/lists.py
async def make_async_request(self, url, params, session, retry=0):
        """Makes an async request using aiohttp.

        Makes a get request.
        If successful, returns the response text future.
        If the request times out, or returns a status code
        that we want to retry, recursively retry the request
        up to MAX_RETRIES times using exponential backoff.

        Args:
            url: The url to make the request to.
            params: The HTTP GET parameters.
            session: The aiohttp ClientSession to make requests with.
            retry: The number of previous attempts at this individual
                request.

        Returns:
            An asyncio future, which, when awaited,
            contains the request response.

        Throws:
            MailChimpImportError: The request keeps returning a bad HTTP status
                code and/or timing out with no response.
        """
        try:

            # Make the async request with aiohttp
            async with session.get(url, params=params,
                                   auth=BasicAuth('shorenstein',
                                                  self.api_key),
                                   proxy=self.proxy) as response:

                # If we got a 200 OK, return the request response
                if response.status == 200:
                    return await response.text()

                # Always log the bad response
                self.logger.warning('Received invalid response code: '
                                    '%s. URL: %s. API key: %s. '
                                    'Response: %s.', response.status,
                                    url, self.api_key,
                                    response.reason)

                # Retry if we got an error
                # And we haven't already retried a few times
                if (response.status in self.HTTP_STATUS_CODES_TO_RETRY
                        and retry < self.MAX_RETRIES):

                    # Increment retry count, log, sleep and then retry
                    retry += 1
                    self.logger.info('Retrying (%s)', retry)
                    await asyncio.sleep(self.BACKOFF_INTERVAL ** retry)
                    return await self.make_async_request(
                        url, params, session, retry)

                # Prepare some details for the user
                error_details = OrderedDict([
                    ('err_desc', 'An error occurred when '
                                 'trying to import your data '
                                 'from MailChimp.'),
                    ('mailchimp_err_code', response.status),
                    ('mailchimp_url', url),
                    ('api_key', self.api_key),
                    ('mailchimp_err_reason', response.reason)])

                # Log the error and raise an exception
                self.logger.exception('Invalid response code from MailChimp')
                raise MailChimpImportError(
                    'Invalid response code from MailChimp',
                    error_details)

        # Catch proxy problems as well as potential asyncio timeouts/disconnects
        except Exception as e: # pylint: disable=invalid-name

            exception_type = type(e).__name__

            # If we're just catching the exception raised above
            # don't need to do anything else
            if exception_type == 'MailChimpImportError':
                raise

            # Otherwise, log what happened as appropriate
            if exception_type == 'ClientHttpProxyError':
                self.logger.warning('Failed to connect to proxy! Proxy: %s',
                                    self.proxy)

            elif exception_type == 'ServerDisconnectedError':
                self.logger.warning('Server disconnected! URL: %s. API key: '
                                    '%s.', url, self.api_key)

            elif exception_type == 'TimeoutError':
                self.logger.warning('Asyncio request timed out! URL: %s. '
                                    'API key: %s.', url, self.api_key)

            else:
                self.logger.warning('An unforseen error type occurred. '
                                    'Error type: %s. URL: %s. API Key: %s.',
                                    exception_type, url, self.api_key)

            # Retry if we haven't already retried a few times
            if retry < self.MAX_RETRIES:

                # Increment retry count, log, sleep, and then retry
                retry += 1
                self.logger.info('Retrying (%s)', retry)
                await asyncio.sleep(self.BACKOFF_INTERVAL ** retry)
                return await self.make_async_request(
                    url, params, session, retry)

            # Prepare some details for the user
            error_details = OrderedDict([
                ('err_desc', 'An error occurred when '
                             'trying to import your data from MailChimp.'),
                ('application_exception', exception_type),
                ('mailchimp_url', url),
                ('api_key', self.api_key)])

            # Log the error and raise an exception
            self.logger.exception('Error in async request to MailChimp (%s)',
                                  exception_type)

            raise MailChimpImportError(
                'Error in async request to MailChimp ({})'.format(
                    exception_type),
                error_details)
Makes an async request using aiohttp.

        Makes a get request.
        If successful, returns the response text future.
        If the request times out, or returns a status code
        that we want to retry, recursively retry the request
        up to MAX_RETRIES times using exponential backoff.

        Args:
            url: The url to make the request to.
            params: The HTTP GET parameters.
            session: The aiohttp ClientSession to make requests with.
            retry: The number of previous attempts at this individual
                request.

        Returns:
            An asyncio future, which, when awaited,
            contains the request response.

        Throws:
            MailChimpImportError: The request keeps returning a bad HTTP status
                code and/or timing out with no response.
        
Makes an async request using aiohttp.
Makes a get request.
If successful, returns the response text future.
If the request times out, or returns a status code
that we want to retry, recursively retry the request
up to MAX_RETRIES times using exponential backoff.
Makes an async request using aiohttp . Makes a get request . If successful returns the response text future . If the request times out or returns a status code that we want to retry recursively retry the request up to MAX_RETRIES times using exponential backoff .
async def make_async_request(self, url, params, session, retry=0):
        try:
            async with session.get(url, params=params,
                                   auth=BasicAuth('shorenstein',
                                                  self.api_key),
                                   proxy=self.proxy) as response:
                if response.status == 200:
                    return await response.text()
                self.logger.warning('Received invalid response code: '
                                    '%s. URL: %s. API key: %s. '
                                    'Response: %s.', response.status,
                                    url, self.api_key,
                                    response.reason)
                if (response.status in self.HTTP_STATUS_CODES_TO_RETRY
                        and retry < self.MAX_RETRIES):
                    retry += 1
                    self.logger.info('Retrying (%s)', retry)
                    await asyncio.sleep(self.BACKOFF_INTERVAL ** retry)
                    return await self.make_async_request(
                        url, params, session, retry)
                error_details = OrderedDict([
                    ('err_desc', 'An error occurred when '
                                 'trying to import your data '
                                 'from MailChimp.'),
                    ('mailchimp_err_code', response.status),
                    ('mailchimp_url', url),
                    ('api_key', self.api_key),
                    ('mailchimp_err_reason', response.reason)])
                self.logger.exception('Invalid response code from MailChimp')
                raise MailChimpImportError(
                    'Invalid response code from MailChimp',
                    error_details)
        except Exception as e: 
            exception_type = type(e).__name__
            if exception_type == 'MailChimpImportError':
                raise
            if exception_type == 'ClientHttpProxyError':
                self.logger.warning('Failed to connect to proxy! Proxy: %s',
                                    self.proxy)
            elif exception_type == 'ServerDisconnectedError':
                self.logger.warning('Server disconnected! URL: %s. API key: '
                                    '%s.', url, self.api_key)
            elif exception_type == 'TimeoutError':
                self.logger.warning('Asyncio request timed out! URL: %s. '
                                    'API key: %s.', url, self.api_key)
            else:
                self.logger.warning('An unforseen error type occurred. '
                                    'Error type: %s. URL: %s. API Key: %s.',
                                    exception_type, url, self.api_key)
            if retry < self.MAX_RETRIES:
                retry += 1
                self.logger.info('Retrying (%s)', retry)
                await asyncio.sleep(self.BACKOFF_INTERVAL ** retry)
                return await self.make_async_request(
                    url, params, session, retry)
            error_details = OrderedDict([
                ('err_desc', 'An error occurred when '
                             'trying to import your data from MailChimp.'),
                ('application_exception', exception_type),
                ('mailchimp_url', url),
                ('api_key', self.api_key)])
            self.logger.exception('Error in async request to MailChimp (%s)',
                                  exception_type)
            raise MailChimpImportError(
                'Error in async request to MailChimp ({})'.format(
                    exception_type),
                error_details)
async def make_async_request ( self , url , params , session , retry = 0 ) : try : async with session . get ( url , params = params , auth = BasicAuth ( 'shorenstein' , self . api_key ) , proxy = self . proxy ) as response : if response . status == 200 : return await response . text ( ) self . logger . warning ( 'Received invalid response code: ' '%s. URL: %s. API key: %s. ' 'Response: %s.' , response . status , url , self . api_key , response . reason ) if ( response . status in self . HTTP_STATUS_CODES_TO_RETRY and retry < self . MAX_RETRIES ) : retry += 1 self . logger . info ( 'Retrying (%s)' , retry ) await asyncio . sleep ( self . BACKOFF_INTERVAL ** retry ) return await self . make_async_request ( url , params , session , retry ) error_details = OrderedDict ( [ ( 'err_desc' , 'An error occurred when ' 'trying to import your data ' 'from MailChimp.' ) , ( 'mailchimp_err_code' , response . status ) , ( 'mailchimp_url' , url ) , ( 'api_key' , self . api_key ) , ( 'mailchimp_err_reason' , response . reason ) ] ) self . logger . exception ( 'Invalid response code from MailChimp' ) raise MailChimpImportError ( 'Invalid response code from MailChimp' , error_details ) except Exception as e : exception_type = type ( e ) . __name__ if exception_type == 'MailChimpImportError' : raise if exception_type == 'ClientHttpProxyError' : self . logger . warning ( 'Failed to connect to proxy! Proxy: %s' , self . proxy ) elif exception_type == 'ServerDisconnectedError' : self . logger . warning ( 'Server disconnected! URL: %s. API key: ' '%s.' , url , self . api_key ) elif exception_type == 'TimeoutError' : self . logger . warning ( 'Asyncio request timed out! URL: %s. ' 'API key: %s.' , url , self . api_key ) else : self . logger . warning ( 'An unforseen error type occurred. ' 'Error type: %s. URL: %s. API Key: %s.' , exception_type , url , self . api_key ) if retry < self . MAX_RETRIES : retry += 1 self . logger . info ( 'Retrying (%s)' , retry ) await asyncio . sleep ( self . BACKOFF_INTERVAL ** retry ) return await self . make_async_request ( url , params , session , retry ) error_details = OrderedDict ( [ ( 'err_desc' , 'An error occurred when ' 'trying to import your data from MailChimp.' ) , ( 'application_exception' , exception_type ) , ( 'mailchimp_url' , url ) , ( 'api_key' , self . api_key ) ] ) self . logger . exception ( 'Error in async request to MailChimp (%s)' , exception_type ) raise MailChimpImportError ( 'Error in async request to MailChimp ({})' . format ( exception_type ) , error_details )
Makes an async request using aiohttp.
Makes an async request using aiohttp .
"""Makes an async request using aiohttp.

        Makes a get request.
        If successful, returns the response text future.
        If the request times out, or returns a status code
        that we want to retry, recursively retry the request
        up to MAX_RETRIES times using exponential backoff.

        Args:
            url: The url to make the request to.
            params: The HTTP GET parameters.
            session: The aiohttp ClientSession to make requests with.
            retry: The number of previous attempts at this individual
                request.

        Returns:
            An asyncio future, which, when awaited,
            contains the request response.

        Throws:
            MailChimpImportError: The request keeps returning a bad HTTP status
                code and/or timing out with no response.
        """ # Make the async request with aiohttp
 # If we got a 200 OK, return the request response
 # Always log the bad response
 # Retry if we got an error
 # And we haven't already retried a few times
 # Increment retry count, log, sleep and then retry
 # Prepare some details for the user
 # Log the error and raise an exception
 # Catch proxy problems as well as potential asyncio timeouts/disconnects
 # pylint: disable=invalid-name
 # If we're just catching the exception raised above
 # don't need to do anything else
 # Otherwise, log what happened as appropriate
 # Retry if we haven't already retried a few times
 # Increment retry count, log, sleep, and then retry
 # Prepare some details for the user
 # Log the error and raise an exception

An asyncio future, which, when awaited,
contains the request response.
An asyncio future which when awaited contains the request response .
self
url
The url to make the request to.
The url to make the request to .
params
The HTTP GET parameters.
The HTTP GET parameters .
session
The aiohttp ClientSession to make requests with.
The aiohttp ClientSession to make requests with .
retry
The number of previous attempts at this individual
request.
The number of previous attempts at this individual request .