'Sync organizations from GitHub API'

def sync_organizations(self):

    try:
        orgs = self.paginate('https://api.github.com/user/orgs')
        for org in orgs:
            org_resp = self.get_session().get(org['url'])
            org_obj = self.create_organization(org_resp.json())
            org_repos = self.paginate('{org_url}/repos'.format(org_url=org['url']))
            for repo in org_repos:
                self.create_repository(repo, organization=org_obj)
    except (TypeError, ValueError) as e:
        log.error('Error    syncing    GitHub    organizations:    %s', str(e), exc_info=True)
        raise Exception('Could    not    sync    your    GitHub    organizations,    try    reconnecting    your    account')
