Error message:
{{{
Internal Server Error: /login
Traceback (most recent call last):
File "<projekt path>/venv/lib/python3.11/site-
packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/django/views/generic/base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/django/contrib/auth/mixins.py", line 73, in dispatch
return super().dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/revproxy/views.py", line 247, in dispatch
response = get_django_response(proxy_response,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/revproxy/response.py", line 64, in get_django_response
response.set_cookie(**cookie_dict)
File "<projekt path>/venv/lib/python3.11/site-
packages/django/http/response.py", line 264, in set_cookie
self.cookies[key]["expires"] = http_date(time.time() + max_age)
~~~~~~~~~~~~^~~~~~~~~
TypeError: unsupported operand type(s) for +: 'float' and 'str'
ERROR:django.request:Internal Server Error: /login
Traceback (most recent call last):
File "<projekt path>/venv/lib/python3.11/site-
packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/django/views/generic/base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/django/contrib/auth/mixins.py", line 73, in dispatch
return super().dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/revproxy/views.py", line 247, in dispatch
response = get_django_response(proxy_response,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<projekt path>/venv/lib/python3.11/site-
packages/revproxy/response.py", line 64, in get_django_response
response.set_cookie(**cookie_dict)
File "<projekt path>/venv/lib/python3.11/site-
packages/django/http/response.py", line 264, in set_cookie
self.cookies[key]["expires"] = http_date(time.time() + max_age)
~~~~~~~~~~~~^~~~~~~~~
TypeError: unsupported operand type(s) for +: 'float' and 'str'
}}}
----
The error gets thrown in {{{HttpResponseBase}}}-class in the
{{{set_cookie}}}-method and it should be easy to fix.
Currently, the important part of the {{{set_cookie}}}-method looks as
follows:
{{{
if max_age is not None:
if isinstance(max_age, datetime.timedelta):
max_age = max_age.total_seconds()
self.cookies[key]["max-age"] = int(max_age)
# IE requires expires, so set it if hasn't been already.
if not expires:
self.cookies[key]["expires"] = http_date(time.time() +
max_age)
}}}
\\
In the last line of this snipped (line 264 in the response.py)
{{{max_age}}} is a string and should be converted to int before adding it
to {{{time.time()}}}.
The code fix could look like this:
{{{
self.cookies[key]["expires"] = http_date(time.time() + int(max_age))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35066>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
Thanks for this report, however `str` is not supported as `max_age` as
[https://docs.djangoproject.com/en/5.0/ref/request-
response/#django.http.HttpResponse.set_cookie documented]:
> ''`max_age` should be a `timedelta` object, an integer number of
seconds, or None''
--
Ticket URL: <https://code.djangoproject.com/ticket/35066#comment:1>