title: Python requests lib, is requests.Session equivalent to urllib2's opener?
body: <p>I need to accomplish a login task in my own project.Luckily I found someone has it done already.<br>
  Here is the related code.</p>
  
  <pre><code>import re,urllib,urllib2,cookielib
  
  class Login():   
      cj = cookielib.LWPCookieJar()     
      opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))  
  
  def __init__(self,name='',password='',domain=''):  
      self.name=name  
      self.password=password  
      self.domain=domain  
      urllib2.install_opener(self.opener)  
  
  def login(self):  
      params = {'domain':self.domain,'email':self.name,'password':self.password}  
      req = urllib2.Request(  
          website_url,  
          urllib.urlencode(params)  
      )  
  
      self.openrate = self.opener.open(req)  
  
      print self.openrate.geturl()  
      info = self.openrate.read()  
  </code></pre>
  
  <p>I've tested the code, it works great (according to <code>info</code>).<br>
  Now I want to port it to Python 3 as well as using <a href="http://docs.python-requests.org/en/latest/" rel="nofollow noreferrer"><code>requests</code></a> lib instead of urllib2.<br>
  My thoughts:</p>
  
  <ol>
  <li>since the original code use <code>opener</code>, though not sure, I think its equivalent in <code>requests</code> is <a href="http://docs.python-requests.org/en/latest/user/advanced/#session-objects" rel="nofollow noreferrer"><code>requests.Session</code></a>  </li>
  <li>Am I supposed to pass in a <code>jar = cookiejar.CookieJar()</code> when making request? Not sure either.</li>
  </ol>
  
  <p>I've tried something like</p>
  
  <pre><code>import requests
  from http import cookiejar
  from urllib.parse import urlencode
  
  jar = cookiejar.CookieJar()
  s = requests.Session()
  s.post(  
      website_url,  
      data = urlencode(params),
      allow_redirects = True,
      cookies = jar  
  ) 
  </code></pre>
  
  <p>Also, followed the answer in <a href="https://stackoverflow.com/questions/6878418/putting-a-cookie-in-a-cookiejar">Putting a `Cookie` in a `CookieJar`</a>, I tried making the same request again, but none of these worked.</p>
  
  <p>That's why I'm here for help.<br>
  Will someone show me the right way to do this job? Thank you~ </p>