I want to be able to leave my twython application running for long periods with no user interaction. It simply prints out tweets directed at me. The program is working but after a while I get the following error :
HTTPSConnectionPool(host='api.twitter.com', port=443): Max retries exceeded with url: /1.1/statuses/mentions_timeline.json?count=20&since_id=392227122070056960 (Caused by <class 'socket.error'>: [Errno 104] Connection reset by peer)
I am using the REST API, not streaming. The twython object is created with :
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
I then retrieve mentions with :
mentions = twitter.get_mentions_timeline(count=20,since_id=sinceID)
The code re-checks every 10 minutes or so, keeping track of the latest since_id, and so only prints out new tweets.
Questions:
1) Is the error a twython error or a python networking library error?
2) In the event of this error, what is the correct way to re-establish the connection with the twitter server without re-starting the program? Do I need to destroy the twython object first and then re-create it and so re-authenticate with the server? In the twython documentation I can only find mention of closing a connection when using the streaming API.
Any advice greatly appreciated.