Ejemplo n.º 1
0
 def __init__(self, entry_point=None, debug=None):
     self._api_call_count = 0
     self.entry_point = entry_point or lithium_settings.get("ENTRY_POINT")
     self.session_key = ""
     if lithium_settings.get("HTTP_USER"):
         auth = (lithium_settings.get("HTTP_USER"), lithium_settings.get("HTTP_PASSWORD"))
     else:
         auth = ()
     self.session = requests.Session()
     self.session.auth = auth
     self.set_debug(lithium_settings.get("DEBUG") if debug is None else debug)
Ejemplo n.º 2
0
 def __init__(self, entry_point=None, debug=None):
     self._api_call_count = 0
     self.entry_point = entry_point or lithium_settings.get('ENTRY_POINT')
     self.session_key = ''
     if lithium_settings.get('HTTP_USER'):
         auth = (lithium_settings.get('HTTP_USER'), lithium_settings.get('HTTP_PASSWORD'))
     else:
         auth = ()
     self.session = requests.Session()
     self.session.auth = auth
     self.set_debug(lithium_settings.get('DEBUG') if debug is None else debug)
Ejemplo n.º 3
0
    def authenticate(self, username, password=None, force_reauth=False):
        """
        Authenticate with the REST API.

        After successfully authenticated, all following API calls automatically
        send the session key.

        :param username: the user name to be used for API calls
        :param password: the password. This can also be set using the ``LITHIUM_API_USERS`` setting
        :param force_reauth: if ``True``, a new authentication token is fetched even if one is available already
        :raise: :class:`~django_lithium_api.exceptions.AuthenticationError`, :class:`django_lithium_api.exceptions.RemoteException`
        """
        if self.session_key and not force_reauth:
            return
        if password is None:
            try:
                password = lithium_settings.get("USERS")[username]
            except KeyError:
                raise exceptions.AuthenticationError('No password set in LITHIUM_API_USERS for "%s".' % username)
        self.session_key = self.call("auth_login", data={"user.login": username, "user.password": password})