by Rene » Sun Jun 10, 2018 4:29 pm
I used the following sample code on the raspberry pi to see if the PI itself is having issues connecting to PushOver. Sure enough, it does. Eventually it runs but it takes a long time. So, I profiles the code using "python -m cProfile testPushOver.py" and it indicates that the socket connection was taking all the time in a call to "{method 'connect' of '_socket.socket' objects}". I adjusted the code (as shown below) with a timeout parameter on the connection. Now the script runs without lag! I compared the results on another computer (no a PI) to see if there was lag and the first script was fine. I think I can conclude that the call to establish the SSL connection is timing out but I don't know why and the web app does not provide a connection timeout parameter. So, still stuck but a step closer to figuring out the issue.
import httplib, urllib
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": "{app token}",
"user": "{user token}",
"message": "hello world",
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
Made this change on the second line.
conn = httplib.HTTPSConnection('api.pushover.net',443, timeout=1)