<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_experiments(experiment_ids=None, user_id=None, client_id=None, bucket_if_necessary=True, user_data=None):
 """ Retrieve the experiments the user is a part of @param experiment_ids : Either a single or list of experiment ids to retreive @param user_id : An identifier for the user @param client_id : Bernoulli Client ID - will default to BERNOULLI_CLIENT_ID ENV variable @param bucket_if_necessary : Choose a variant for the user if one has not been chosen @param user_data : Dictionary of user information to be used by the segment filters """


    if not client_id:
        client_id = os.environ.get('BERNOULLI_CLIENT_ID')

    if not client_id:
        raise Exception("client_id is required")

    if type(experiment_ids) is dict:
        experiment_ids = ','.join(experiment_ids)

    params = {
        'clientId': client_id,
        'experimentIds': experiment_ids,
        'userId': user_id,
        'bucketIfNecessary': bucket_if_necessary,
    }

    if user_data is None:
        user_data = {}

    try:
        response = requests.get(BASE_URL, params=dict(params.items() + user_data.items()))
    except requests.ConnectionError:
        raise Exception("Unable to access service")

    val = response.json()
    if val['status'] != 'ok':
        raise Exception(val['message'])

    return val['value']