﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35066	Unsupported operand exception in response.py	PaddyKe	nobody	"Hi, when using the [https://github.com/jazzband/django-revproxy Django-Revproxy Plugin] I stumbled across an error when cookies are being set.

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))
}}}"	Bug	closed	HTTP handling	5.0	Normal	invalid			Unreviewed	0	0	0	0	1	0
