(web_user, retry_num=0)
return None
Attempts to match a web_user with a hubspot vid if that web user's email is
    in hubspot.
    :param web_user: WebUser
    :param retry_num: the number of the current retry attempt
    :return: string or None
Attempts to match a web_user with a hubspot vid if that web user's email is
    in hubspot.
    :param web_user: WebUser
    :param retry_num: the number of the current retry attempt
    :return: string or None
Attempts to match a web_user with a hubspot vid if that web user s email is in hubspot . : param web_user : WebUser : param retry_num : the number of the current retry attempt : return : string or None
def _get_user_hubspot_id(web_user, retry_num=0):
    """
    Attempts to match a web_user with a hubspot vid if that web user's email is
    in hubspot.
    :param web_user: WebUser
    :param retry_num: the number of the current retry attempt
    :return: string or None
    """
    if retry_num > 0:
        time.sleep(10)  # wait 10 seconds if this is another retry attempt

    api_key = settings.ANALYTICS_IDS.get('HUBSPOT_API_KEY', None)
    if api_key and hubspot_enabled_for_user(web_user):
        try:
            req = requests.get(
                "https://api.hubapi.com/contacts/v1/contact/email/{}/profile".format(
                    six.moves.urllib.parse.quote(web_user.username)
                ),
                params={'hapikey': api_key},
            )
            if req.status_code == 404:
                return None
            req.raise_for_status()
        except (ConnectionError, requests.exceptions.HTTPError) as e:
            if retry_num <= MAX_API_RETRIES:
                return _get_user_hubspot_id(web_user, retry_num + 1)
            else:
                metrics_counter(
                    'commcare.hubspot.get_user_hubspot_id.retry_fail'
                )
                logger.error(f"Failed to get Hubspot user id for WebUser "
                             f"{web_user.username} due to {str(e)}.")
        else:
            metrics_counter(
                'commcare.hubspot.get_user_hubspot_id.success'
            )
            return req.json().get("vid", None)
    elif api_key and retry_num == 0:
        metrics_counter(
            'commcare.hubspot.get_user_hubspot_id.rejected'
        )
    return None
def _get_user_hubspot_id ( web_user , retry_num = 0 ) : if retry_num > 0 : time . sleep ( 10 ) # wait 10 seconds if this is another retry attempt api_key = settings . ANALYTICS_IDS . get ( 'HUBSPOT_API_KEY' , None ) if api_key and hubspot_enabled_for_user ( web_user ) : try : req = requests . get ( "https://api.hubapi.com/contacts/v1/contact/email/{}/profile" . format ( six . moves . urllib . parse . quote ( web_user . username ) ) , params = { 'hapikey' : api_key } , ) if req . status_code == 404 : return None req . raise_for_status ( ) except ( ConnectionError , requests . exceptions . HTTPError ) as e : if retry_num <= MAX_API_RETRIES : return _get_user_hubspot_id ( web_user , retry_num + 1 ) else : metrics_counter ( 'commcare.hubspot.get_user_hubspot_id.retry_fail' ) logger . error ( f"Failed to get Hubspot user id for WebUser " f"{web_user.username} due to {str(e)}." ) else : metrics_counter ( 'commcare.hubspot.get_user_hubspot_id.success' ) return req . json ( ) . get ( "vid" , None ) elif api_key and retry_num == 0 : metrics_counter ( 'commcare.hubspot.get_user_hubspot_id.rejected' ) return None