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.
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
1]Login (can do only once)
2]Post the request to server
3]Keep monitoring output of step 2 eternally whenever there is some output log it into a file
4]Keep the session alive by another request to server.
Let me know if you need more explanation.
Below is code, it does not work though
while True:try:xmldata = "<eventSubscribe cookie=\"%s\" />" % (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 eself.write_to_file('Ok',"")self.login()
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.
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.