title: Python authentication cookies and django sessions
body: <p>I am trying to create an external python client to access a django app. The client should authenticate a user, generate cookies and be able to access the pages just like any browser.</p>
  
  <pre><code>login_data_encoded = urllib.urlencode({'user':'sample', 'pass':'secret'})
  cj = cookielib.CookieJar()
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  urllib2.install_opener(opener)
  opener.open('http://localhost:8000/login', login_data_encoded)  #problem here
  response = opener.open('http://localhost:8000/secret_page')
  secret_page = response.read()
  </code></pre>
  
  <p>In python interpreter:</p>
  
  <pre><code>import client
  
  client.secret_page
  --&gt; []
  </code></pre>
  
  <p>But the page is empty. I can view the page in browser (once logged in as sample user, login works). Django identified me as an Anonymous User (thus due to permissions, it does not let me view the data for sample user) maybe because I have not started a django session for the user. How do I start a django session through the client? (not with a browser)</p>
  
  <p>I hope I have made this clear.</p>
  
  <p>EDIT 1:</p>
  
  <p>It logs me in as Anonymous user, no difference with or without slash. No csrf in code or template. Log of Django shows 200 response, and 200 on getting the secret_page as well. cj contains the cookie information:</p>
  
  <pre><code>&lt;cookielib.CookieJar[Cookie(version=0, name='app_r12', value='dd070f7acfe37c0474c223287c5adcbe', port=None, port_specified=False, domain='localhost.local', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={}, rfc2109=False)]&gt;
  </code></pre>
  
  <p>The response for opener.open (the POST one) is again 200 and url is the same. </p>