Here is the code I am working with.
import requests
headers = { 'Accept':'*/*',
'Accept-Language':'en-US,en;q=0.8',
'Cookie':'Cookie:PHPSESSID=vev1ekv3grqhh37e8leu1coob1',
'Cache-Control':'max-age=0',
'Connection':'keep-alive',
'Proxy-Authorization':'Basic ZWRjZ3Vlc3Q6ZWRjZ3Vlc3Q=',
'If-Modified-Since':'Fri, 13 Nov 2015 17:47:23 GMT',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'
}
with requests.Session() as c:
url = 'http://172.31.13.135/tpo/spp/'
c.get(url, headers=headers)
payload = {'regno': 'myregno', 'password': 'mypassword'}
c.post(url, data = payload, headers=headers)
r = c.get('http://172.31.13.135/tpo/spp/home.php', headers=headers)
print r.content
I get the following message when I run this script.
<script>
alert("Session timeout !");
window.location = "logout.php";
</script><script>
alert("Unauthorised Access!");
window.location = "index.php";
</script>
<!DOCTYPE html>
<html lang="en">
How do I deal with this "session timeout" issue ?
Many thanks in advance.
You could also just pass the timeout variable in your get and post method:
timeout = 10 # ten sec.
with requests.Session() as c:
url = 'http://172.31.13.135/tpo/spp/'
c.get(url, headers=headers, timeout=timeout)
payload = {'regno': 'myregno', 'password': 'mypassword'}
c.post(url, data = payload, headers=headers, timeout=timeout)
r = c.get('http://172.31.13.135/tpo/spp/home.php', headers=headers, timeout=timeout)
print r.content
You could tweak the max time you wan to wait for a response by doing this For more about request see the docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With