[Fixed]-How do I convince Django I'm logged in?

0👍

It appeared that Set-Cookie is a wrong header for consequent requests. Cookie should be used instead:

>>> get = Request('http://127.0.0.1:8000/api/do-stuff')
>>> get.add_header('Cookie', 'csrftoken=53eX5pwRzV4fR...')  # just csrftoken here
>>> get_resp = urlopen(get)

1👍

Try to use Django’s test client instead of urllib.

>>> from django.test import Client
>>> c = Client()
>>> response = c.post('/login/', {'username': 'john', 'password': 'smith'})
>>> response.status_code
200
>>> response = c.get('/customer/details/')
>>> response.content
b'<!DOCTYPE html...'

See: documentation

Leave a comment