<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_token(self, user, password):
 """Takes user and password credentials and generates a new token :param user: user :param password: password :return: - dictionary containing token data :raises: - TokenCreateError: If there was an error generating the new token """


        logger.debug('(TOKEN_CREATE) :: User: %s' % user)

        session = OAuth2Session(client=LegacyApplicationClient(client_id=self.client_id))

        try:
            return dict(session.fetch_token(token_url=self.token_url,
                                            username=user,
                                            password=password,
                                            client_id=self.client_id,
                                            client_secret=self.client_secret))
        except OAuth2Error as exception:
            raise TokenCreateError('Error creating user token', exception.description, exception.status_code)