Skip to content

Commit

Permalink
handling ConnectionError
Browse files Browse the repository at this point in the history
  • Loading branch information
NNTin committed Jan 10, 2019
1 parent a5a3ae8 commit a1786d4
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import re
from config import data_json
import urllib3
import requests


class StdOutListener(StreamListener):
Expand Down Expand Up @@ -268,24 +269,24 @@ def on_warning(self, notice):

print('Twitter stream started.')
while True:
try:
stream.filter(follow=data_json['twitter_ids'])
except urllib3.exceptions.ProtocolError as error:
def print_error(_error):
print('---------Error---------')
print('This is probably caused by "Connection reset by peer." Ignore. Nothing you can do.')
print(error)
print('Sleeping for 10 seconds then continuing.')
sleep(10)
print('Known error. Ignore. Nothing you can do.')
print(_error)
print('Sleeping for 1 minute then continuing.')
sleep(600)
print('Twitter streaming continues.')
print('-----------------------')
try:
stream.filter(follow=data_json['twitter_ids'])
except urllib3.exceptions.ProtocolError as error:
print_error(_error=error)
except ConnectionResetError as error:
print('---------Error---------')
print('This is probably caused by "Connection reset by peer." Ignore. Nothing you can do.')
print(error)
print('Sleeping for 10 seconds then continuing.')
sleep(10)
print('Twitter streaming continues.')
print('-----------------------')
print_error(_error=error)
except ConnectionError as error:
print_error(_error=error)
except requests.exceptions.ConnectionError as error:
print_error(_error=error)
except Exception as error:
print('---------Error---------')
print('unknown error')
Expand Down

0 comments on commit a1786d4

Please sign in to comment.