python-tvrage
python-tvrage copied to clipboard
TVRage connection forcibly closed
I am getting
tvrage error [Errno 10054] An existing connection was forcibly closed by the remote host.
I think this relates to urllib2 and the connection timing out. Is there a way to keep the connection alive? I have seen some mention of this issue on stackoverflow with a few solutions, one of which includes moving to urllib3.
Actually it has to do with the server being overloaded (see the first comment here: http://www.reddit.com/r/learnpython/comments/1wqxv8/connection_forcibly_closing_err_10054_in_web/) That "exponential backoff" would look something like this:
sleepTime = 1.0
while True:
try:
tvrage.quickinfo.fetch(some_showname)
break
except TvrageError, e:
if str(e).startswith("[Errno 10054]"):
sleepTime *= 2
time.sleep(sleepTime)
else:
raise e
you should stop the loop at some point though, e.g. via a maximum number of retries. Additionally you could limit the number of request per minute (if you are querying a lot of shows)