How to use the stravalib.exc function in stravalib

To help you get started, weโ€™ve selected a few stravalib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hozn / stravalib / stravalib / client.py View on Github external
:type poll_interval: float

        :return: The uploaded Activity object (fetched from server)
        :rtype: :class:`stravalib.model.Activity`

        :raise stravalib.exc.TimeoutExceeded: If a timeout was specified and
                                              activity is still processing after
                                              timeout has elapsed.
        :raise stravalib.exc.ActivityUploadFailed: If the poll returns an error.
        """
        start = time.time()
        while self.activity_id is None:
            self.poll()
            time.sleep(poll_interval)
            if timeout and (time.time() - start) > timeout:
                raise exc.TimeoutExceeded()
        # If we got this far, we must have an activity!
        return self.client.get_activity(self.activity_id)
github hozn / stravalib / stravalib / model.py View on Github external
def stats(self):
        """
        :return: Associated :class:`stravalib.model.AthleteStats`
        """
        if not self.is_authenticated_athlete():
            raise exc.NotAuthenticatedAthlete("Statistics are only available for the authenticated athlete")
        if self._stats is None:
            self.assert_bind_client()
            self._stats = self.bind_client.get_athlete_stats(self.id)
        return self._stats
github hozn / stravalib / stravalib / util / limiter.py View on Github external
def _raise_rate_limit_timeout(self, timeout, limit_rate):
        raise exc.RateLimitTimeout("Rate limit of {0} exceeded. "
                                   "Try again in {1} seconds.".format(limit_rate, timeout),
                                   limit=limit_rate, timeout=timeout)
github hozn / stravalib / stravalib / protocol / scrape.py View on Github external
token_name = soup.find('meta', attrs=dict(name="csrf-param"))['content']
        token_value = soup.find('meta', attrs=dict(name="csrf-token"))['content']
        
        r = self.rsession.post('https://www.strava.com/session',
                               data={'email': self.creds.username,
                                     'password': self.creds.password,
                                     'plan': '',
                                     'utf8': u'โœ“',
                                     token_name: token_value},
                               cookies=r.cookies)
        
        soup = BeautifulSoup(r.text)
        #print r.text
        #print "Page title: %s" % soup.title.string
        if soup.title.string.startswith('Log In'):
            raise exc.LoginFailed("Login failed.")
        
        self.cookies = r.cookies
github hozn / stravalib / stravalib / protocol.py View on Github external
"""
        error_str = None
        try:
            json_response = response.json()
        except ValueError:
            pass
        else:
            if 'message' in json_response or 'errors' in json_response:
                error_str = '{0}: {1}'.format(json_response.get('message', 'Undefined error'), json_response.get('errors'))

        # Special subclasses for some errors
        msg = None
        exc_class = None
        if response.status_code == 404:
            msg = '%s: %s' % (response.reason, error_str)
            exc_class = exc.ObjectNotFound
        elif response.status_code == 401:
            msg = '%s: %s' % (response.reason, error_str)
            exc_class = exc.AccessUnauthorized
        elif 400 <= response.status_code < 500:
            msg = '%s Client Error: %s [%s]' % (response.status_code, response.reason, error_str)
            exc_class = exc.Fault
        elif 500 <= response.status_code < 600:
            msg = '%s Server Error: %s [%s]' % (response.status_code, response.reason, error_str)
            exc_class = exc.Fault
        elif error_str:
            msg = error_str
            exc_class = exc.Fault

        if exc_class is not None:
            raise exc_class(msg, response=response)
github hozn / stravalib / stravalib / protocol / scrape.py View on Github external
def wrapper(self,*args,**kwargs):
        if not self.authenticated:
            if self.creds:
                self.login()
            else:
                raise exc.LoginRequired("This method requires authentication.")
        return method(self, *args, **kwargs)
    return wrapper
github hozn / stravalib / stravalib / protocol / scrape.py View on Github external
:return: Progress dict for specified file.
        :rtype: dict
        """
        r = self.rsession.get('http://app.strava.com/upload/progress.json',
                              params={'ids[]': upload_id},
                              cookies=self.cookies)
        progress = r.json()
        if not len(progress):
            raise exc.Fault("No matches for upload id: {0}".format(upload_id))
        else:
            for p in progress:
                if p['id'] == upload_id:
                    return p
            else:
                self.log.debug("upload status reponse: {0!r}".format(progress))
                raise exc.Fault("Statuses returned, but no matches for upload id: {0}".format(upload_id))