title: Get continuous response of POST request in python
body: <p>I'm writing a script which does a POST request to a server and gets blocked the server keeps sending the response whenever a specific event is triggered. I have to take a cookie for post request with earlier login request and pass it as data to POST, each cookie lasts for 10 mins after which I've to run keep-alive request.</p>
  
  <p>Whenever some event is triggered I want to log that event in a file, I tried async, unirest requests they generate the post request but I don't have control over output, I tried sessions also but of no use. I want to do following things in same order</p>
  
  <p>1]Login (can do only once)</p>
  
  <p>2]Post the request to server</p>
  
  <p>3]Keep monitoring output of step 2 eternally whenever there is some output log it into a file</p>
  
  <p>4]Keep the session alive by another request to server.</p>
  
  <p>Let me know if you need more explanation.</p>
  
  <p>Below is code, it does not work though</p>
  
  <pre><code>while True:
      try:
          xmldata = "&lt;eventSubscribe cookie=\"%s\" /&gt;" % (self.cookie)
          r = requests.post(post_url,data=xmldata,stream=False,verify=False,timeout=10)
          write_to_file('Ok',r.text)
          unsubevents()
          logout()
      except Exception as e:
          print e
          self.write_to_file('Ok',"")
      self.login()
  </code></pre>
  
  <p>So in above code the post call I make here is blocking and continuous, It streams the output continuously so the post call never really gets completed.
  But it receives output in xml format, server sends these responses every time an event is triggered.</p>
  
  <p>PS: I don't want to do logout and login again,this works in curl where it keeps printing output on stdout, I have to run this code for several servers like 200.</p>