title: Using Python Requests: Sessions, Cookies, and POST
body: <p>I am trying to scrape some selling data using the <a href="https://developer.stubhub.com/store/" rel="noreferrer">StubHub API</a>. An example of this data seen here:</p>
  
  <p><a href="https://sell.stubhub.com/sellapi/event/4236070/section/null/seatmapdata" rel="noreferrer">https://sell.stubhub.com/sellapi/event/4236070/section/null/seatmapdata</a></p>
  
  <p>You'll notice that if you try and visit that url without logging into stubhub.com, it won't work. <a href="https://myaccount.stubhub.com/login/Signin" rel="noreferrer">You will need to login first</a>.</p>
  
  <p>Once I've signed in via my web browser, I open the URL which I want to scrape in a new tab, then use the following command to retrieve the scraped data:</p>
  
  <pre><code>r = requests.get('https://sell.stubhub.com/sellapi/event/4236070/section/null/seatmapdata')
  </code></pre>
  
  <p>However, once the browser session expires after ten minutes, I get this error:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;FormErrors&gt;
  &lt;FormField&gt;User Auth Check&lt;/FormField&gt;
  &lt;ErrorMessage&gt;
  Either is not active or the session might have expired. Please login again.
  &lt;/ErrorMessage&gt;
  </code></pre>
  
  <p>I think that I need to implement the session ID via cookie to keep my authentication alive and well.</p>
  
  <p>The Requests library documentation is pretty terrible for someone who has never done this sort of thing before, so I was hoping you folks might be able to help.</p>
  
  <p>The example provided by Requests is:</p>
  
  <pre><code>s = requests.Session()
  
  s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
  r = s.get("http://httpbin.org/cookies")
  
  print r.text
  # '{"cookies": {"sessioncookie": "123456789"}}'
  </code></pre>
  
  <p>I honestly can't make heads or tails of that. How do I preserve cookies between POST requests?</p>