Exemplo n.º 1
0
    def request(self, method, path=None, params=None, data=None, query=None, authenticated=False,
                validate_token=True, **kwargs):

        # Retrieve configuration
        ctx = self.configuration.pop()

        # Build request
        request = TraktRequest(
            self.client,
            method=method,

            path=self._build_path(ctx, path),
            params=params,

            data=data,
            query=query,

            authenticated=authenticated,
            **kwargs
        )

        # Validate authentication details (OAuth)
        if authenticated and validate_token and not self.validate():
            return None

        # Prepare request
        prepared = request.prepare()

        if not self.keep_alive:
            prepared.headers['Connection'] = 'close'

        # Send request
        return self.send(prepared)
Exemplo n.º 2
0
    def request(self, method, path=None, params=None, data=None, query=None, authenticated=False, **kwargs):
        # Retrieve configuration
        ctx = self.configuration.pop()

        retry = self.client.configuration.get('http.retry', DEFAULT_HTTP_RETRY)
        max_retries = self.client.configuration.get('http.max_retries', DEFAULT_HTTP_MAX_RETRIES)
        retry_sleep = self.client.configuration.get('http.retry_sleep', DEFAULT_HTTP_RETRY_SLEEP)
        timeout = self.client.configuration.get('http.timeout', DEFAULT_HTTP_TIMEOUT)

        # Build request
        request = TraktRequest(
            self.client,
            method=method,

            path=self._build_path(ctx, path),
            params=params,

            data=data,
            query=query,

            authenticated=authenticated,
            **kwargs
        )

        # Validate authentication details (OAuth)
        if authenticated and not self.validate():
            return None

        # Prepare request
        prepared = request.prepare()

        response = None

        for i in range(max_retries + 1):
            if i > 0:
                log.warn('Retry # %s', i)

            # Send request
            try:
                response = self.session.send(prepared, timeout=timeout)
            except socket.gaierror as e:
                code, _ = e

                if code != 8:
                    raise e

                log.warn('Encountered socket.gaierror (code: 8)')

                response = self.rebuild().send(prepared, timeout=timeout)

            # Retry requests on errors >= 500 (when enabled)
            if not retry or response.status_code < 500:
                break

            log.warn('Continue retry since status is %s, waiting %s seconds', response.status_code, retry_sleep)
            time.sleep(retry_sleep)

        return response
Exemplo n.º 3
0
    def request(self, method, path=None, params=None, data=None, query=None, **kwargs):
        # retrieve configuration
        ctx = self.configuration.pop()

        retry = self.client.configuration.get('http.retry', DEFAULT_HTTP_RETRY)
        max_retries = self.client.configuration.get('http.max_retries', DEFAULT_HTTP_MAX_RETRIES)
        retry_sleep = self.client.configuration.get('http.retry_sleep', DEFAULT_HTTP_RETRY_SLEEP)
        timeout = self.client.configuration.get('http.timeout', DEFAULT_HTTP_TIMEOUT)

        # build request
        if ctx.base_path and path:
            path = ctx.base_path + '/' + path
        elif ctx.base_path:
            path = ctx.base_path

        request = TraktRequest(
            self.client,
            method=method,

            path=path,
            params=params,

            data=data,
            query=query,

            **kwargs
        )

        prepared = request.prepare()

        # retrying requests on errors >= 500
        response = None

        for i in range(max_retries + 1):
            if i > 0 :
                log.warn('Retry # %s', i)

            try:
                response = self.session.send(prepared, timeout=timeout)
            except socket.gaierror as e:
                code, _ = e

                if code != 8:
                    raise e

                log.warn('Encountered socket.gaierror (code: 8)')

                response = self.rebuild().send(prepared, timeout=timeout)

            if not retry or response.status_code < 500:
                break

            log.warn('Continue retry since status is %s, waiting %s seconds', response.status_code, retry_sleep)
            time.sleep(retry_sleep)

        return response
Exemplo n.º 4
0
    def request(self, method, path=None, params=None, data=None, **kwargs):
        # retrieve configuration
        ctx = self.configuration.pop()

        retry = self.client.configuration.get('http.retry', DEFAULT_HTTP_RETRY)
        max_retries = self.client.configuration.get('http.max_retries',
                                                    DEFAULT_HTTP_MAX_RETRIES)
        retry_sleep = self.client.configuration.get('http.retry_sleep',
                                                    DEFAULT_HTTP_RETRY_SLEEP)
        timeout = self.client.configuration.get('http.timeout',
                                                DEFAULT_HTTP_TIMEOUT)

        # build request
        if ctx.base_path and path:
            path = ctx.base_path + '/' + path
        elif ctx.base_path:
            path = ctx.base_path

        request = TraktRequest(self.client,
                               method=method,
                               path=path,
                               params=params,
                               data=data,
                               **kwargs)

        prepared = request.prepare()

        # retrying requests on errors >= 500
        response = None

        for i in range(max_retries + 1):
            if i > 0:
                log.warn('Retry # %s', i)

            try:
                response = self.session.send(prepared, timeout=timeout)
            except socket.gaierror as e:
                code, _ = e

                if code != 8:
                    raise e

                log.warn('Encountered socket.gaierror (code: 8)')

                response = self._build_session().send(prepared,
                                                      timeout=timeout)

            if not retry or response.status_code < 500:
                break

            log.warn('Continue retry since status is %s, waiting %s seconds',
                     response.status_code, retry_sleep)
            time.sleep(retry_sleep)

        return response
Exemplo n.º 5
0
    def request(self, method, path=None, params=None, data=None, **kwargs):
        # retrieve configuration
        ctx = self.configuration.pop()

        retry = self.client.configuration.get('http.retry', False)
        max_retries = self.client.configuration.get('http.max_retries', 3)

        # build request
        if ctx.base_path and path:
            path = ctx.base_path + '/' + path
        elif ctx.base_path:
            path = ctx.base_path

        request = TraktRequest(self.client,
                               method=method,
                               path=path,
                               params=params,
                               data=data,
                               **kwargs)

        prepared = request.prepare()

        # retrying requests on errors >= 500
        response = None

        for i in range(max_retries + 1):
            if i > 0:
                log.warn('Retry # %s', i)

            try:
                response = self.session.send(prepared)
            except socket.gaierror, e:
                code, _ = e

                if code != 8:
                    raise e

                log.warn('Encountered socket.gaierror (code: 8)')

                response = self._build_session().send(prepared)

            if not retry or response.status_code < 500:
                break

            log.warn('Continue retry since status is %s', response.status_code)
            time.sleep(5)
Exemplo n.º 6
0
    def request(self, method, path=None, params=None, data=None, **kwargs):
        ctx = self.configuration.pop()

        if ctx.base_path and path:
            path = ctx.base_path + '/' + path
        elif ctx.base_path:
            path = ctx.base_path

        request = TraktRequest(self.client,
                               method=method,
                               path=path,
                               params=params,
                               data=data,
                               **kwargs)

        prepared = request.prepare()

        # retrying requests on errors >= 500
        try:
            for i in range(5):
                if i > 0:
                    log.warn('Retry # %s', i)
                response = self.session.send(prepared)

                if response.status_code < 500:
                    #log.warn('Breaking out of retries with status %s', response.status_code)
                    break
                else:
                    log.warn('Continue retry since status is %s',
                             response.status_code)
                    time.sleep(5)
            return response
        except socket.gaierror, e:
            code, _ = e

            if code != 8:
                raise e

            log.warn('Encountered socket.gaierror (code: 8)')

            return self._rebuild().send(prepared)