Cookies not showing up in environ

Calvin Spealman cspealma at
Fri Jul 20 15:46:56 EDT 2018

You can read cookies from the request via the request.COOKIES dictionary.
See the documentation here:

You won't find them in an environment variable, which is shared
process-wide and across all requests, because they are bound to each
request. This is not a CGI script, so those HTTP_* environment variables
you seem to expect won't be here.

On Fri, Jul 20, 2018 at 3:39 PM, abc abc <useracct222 at> wrote:

> I am trying the simplest of examples below to set and read a cookie. I am
> using the Django framework, but I have also tried with vanilla python
> cookies and os.environ. I have posted elsewhere, but this hasn't gotten
> much attention, so I'd really appreciate any help.
> Thinking at this point it may be something to with the server, not python.
> I have tried uwsgi/nginx, gunicorn/nginx, django development server with no
> success.
> def index(environ, start_response, request):
>     if not 'HTTP_COOKIE' in environ:
>         response = HttpResponse("hello")
>         response.set_cookie('user_agreement', 'cookie text', domain='.
>         return response
>     else:
>         print environ['HTTP_COOKIE']
> The webpage just prints 'hello' and never reaches the else not matter how
> many times I refresh the page. There are no cookies in the browser ever
> either.
> Am I missing some middleware? I remember some answers to cookie problems
> related to the order of their middleware configurations. Here's mine:
>     '',
>     'django.contrib.sessions.middleware.SessionMiddleware',
>     'django.middleware.common.CommonMiddleware',
>     'django.middleware.csrf.CsrfViewMiddleware',
>     'django.contrib.auth.middleware.AuthenticationMiddleware',
>     'django.contrib.messages.middleware.MessageMiddleware',
>     'django.middleware.clickjacking.XFrameOptionsMiddleware',
> ]
> --

More information about the Python-list mailing list