'Set REST client credential from database
:param username: if set, account\'s credential will be used.
:return:'

@with_session
def set_credential(self, username=None, session=None):

    query = session.query(Credential)
    if username:
        query = query.filter((Credential.username == username))
    credential = query.first()
    if (credential is None):
        raise PluginError(u'You    cannot    use    t411    plugin    without    credentials.    Please    set    credential    with    "flexget    t411    add-auth    <username>    <password>".')
    self.__set_credential(credential.username, credential.password, credential.api_token)
