'Loads credentials from the VCAP_SERVICES environment variable if
available, preferring credentials explicitly
set in the request.
If VCAP_SERVICES is not found (or use_vcap_services is set to False),
username and password credentials must
be specified.'

def __init__(self, vcap_services_name, url, username=None, password=None, use_vcap_services=True, api_key=None, x_watson_learning_opt_out=False):

    self.url = url
    self.jar = None
    self.api_key = None
    self.username = None
    self.password = None
    self.x_watson_learning_opt_out = x_watson_learning_opt_out
    if (api_key is not None):
        if ((username is not None) or (password is not None)):
            raise WatsonInvalidArgument('Cannot    set    api_key    and    username    and    password    together')
        self.set_api_key(api_key)
    else:
        self.set_username_and_password(username, password)
    if (use_vcap_services and (not self.username) and (not self.api_key)):
        self.vcap_service_credentials = load_from_vcap_services(vcap_services_name)
        if ((self.vcap_service_credentials is not None) and isinstance(self.vcap_service_credentials, dict)):
            self.url = self.vcap_service_credentials['url']
            if ('username' in self.vcap_service_credentials):
                self.username = self.vcap_service_credentials['username']
            if ('password' in self.vcap_service_credentials):
                self.password = self.vcap_service_credentials['password']
            if ('apikey' in self.vcap_service_credentials):
                self.api_key = self.vcap_service_credentials['apikey']
            if ('api_key' in self.vcap_service_credentials):
                self.api_key = self.vcap_service_credentials['api_key']
    if (((self.username is None) or (self.password is None)) and (self.api_key is None)):
        raise WatsonException(('You    must    specify    your    username    and    password    service    credentials    ' + '(Note:    these    are    different    from    your    Bluemix    id)'))
