code: def _generate_token(self):
          
          session = self.get_session()
          url = self.__base_url('magicBox.cgi?action=getMachineName')
          try:
              # try old basic method
              auth = requests.auth.HTTPBasicAuth(self._user, self._password)
              req = session.get(url, auth=auth, timeout=self._timeout_default)
              if not req.ok:
                  # try new digest method
                  auth = requests.auth.HTTPDigestAuth(
                      self._user, self._password)
                  req = session.get(
                      url, auth=auth, timeout=self._timeout_default)
              req.raise_for_status()
          except requests.RequestException as error:
              _LOGGER.error(error)
              raise CommError('Could not communicate with camera')
  
          # check if user passed
          result = req.text.lower()
          if 'invalid' in result or 'error' in result:
              _LOGGER.error('Result from camera: %s',
                            req.text.strip().replace('\r\n', ': '))
              raise LoginError('Invalid credentials')
  
          return auth
docs: Create authentation to use with requests.