Skip to content
Advertisement

‘microsecond’ is an invalid keyword argument for replace()

I am using Django 2.0+ and am attempting to just plug in the existing password reset function into my website. If the email does not exist, it successfully submits. If it DOES exist, I get this error:

'microsecond' is an invalid keyword argument for replace()

I never touched any of the backend code for this function so I would assume it would just work out of the box.

Traceback:

C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocorehandlersexception.py in inner
            response = get_response(request) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocorehandlersbase.py in _get_response
                response = self.process_exception_by_middleware(e, request) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocorehandlersbase.py in _get_response
                response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangoviewsgenericbase.py in view
            return self.dispatch(request, *args, **kwargs) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangoutilsdecorators.py in _wrapper
        return bound_method(*args, **kwargs) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangoutilsdecorators.py in _wrapped_view
                    response = view_func(request, *args, **kwargs) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocontribauthviews.py in dispatch
        return super().dispatch(*args, **kwargs) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangoviewsgenericbase.py in dispatch
        return handler(request, *args, **kwargs) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangoviewsgenericedit.py in post
            return self.form_valid(form) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocontribauthviews.py in form_valid
        form.save(**opts) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocontribauthforms.py in save
                'token': token_generator.make_token(user), …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocontribauthtokens.py in make_token
        return self._make_token_with_timestamp(user, self._num_days(self._today())) …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocontribauthtokens.py in _make_token_with_timestamp
            self._make_hash_value(user, timestamp), …
▶ Local vars
C:Usersdjankdocumentsgithublfgm_2019libsite-packagesdjangocontribauthtokens.py in _make_hash_value
        login_timestamp = '' if user.last_login is None else user.last_login.replace(microsecond=0, tzinfo=None)

I do have a CustomUser model I use, but I can’t see if there is a connection or, if so, where the connection might be with that.

Help!

Advertisement

Answer

Just go to the tokens.py file (for me, it was located here: AppDataLocalProgramsPythonPython38-32Libsite-packagesdjangocontribauthtokens.py ) and change the following line:

user.last_login.replace(microsecond=0,tzinfo=None)

to

user.last_login.replace()
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement