'Sync repositories from Bitbucket API'

def sync_repositories(self):

    try:
        repos = self.paginate('https://bitbucket.org/api/2.0/repositories/?role=member')
        for repo in repos:
            self.create_repository(repo)
    except (TypeError, ValueError) as e:
        log.error('Error    syncing    Bitbucket    repositories:    %s', str(e), exc_info=True)
        raise Exception('Could    not    sync    your    Bitbucket    repositories,    try    reconnecting    your    account')
    try:
        resp = self.paginate('https://bitbucket.org/api/2.0/repositories/?role=admin')
        repos = RemoteRepository.objects.filter(users=self.user, full_name__in=[r['full_name'] for r in resp], account=self.account)
        for repo in repos:
            repo.admin = True
            repo.save()
    except (TypeError, ValueError):
        pass
