Repository: python-telegram-bot/python-telegram-bot

Issue:
Bot stopps working after reconnect of system
This error appears after some time of running. Because of some reason my wifi reconnects after some time and after this the bot dont get back to work. Any ideas to prevent this? I have to restart the bot every time this happens.

```
Exception in thread updater:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Python27\lib\site-packages\telegram\ext\updater.py", line 146, in _thread_wrapper
    target(*args, **kwargs)
  File "C:\Python27\lib\site-packages\telegram\ext\updater.py", line 223, in _start_polling
    network_delay=network_delay)
  File "C:\Python27\lib\site-packages\telegram\bot.py", line 128, in decorator
    result = func(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\telegram\bot.py", line 796, in getUpdates
    result = request.post(url, data, network_delay=network_delay)
  File "C:\Python27\lib\site-packages\telegram\utils\request.py", line 77, in decorator
    return func(*args, **kwargs)
  File "C:\Python27\lib\site-packages\telegram\utils\request.py", line 173, in post
    result = urlopen(request, **urlopen_kwargs).read()
  File "C:\Python27\lib\urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 431, in open
    response = self._open(req, data)
  File "C:\Python27\lib\urllib2.py", line 449, in _open
    '_open', req)
  File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 1240, in https_open
    context=self._context)
  File "C:\Python27\lib\urllib2.py", line 1200, in do_open
    r = h.getresponse(buffering=True)
  File "C:\Python27\lib\httplib.py", line 1136, in getresponse
    response.begin()
  File "C:\Python27\lib\httplib.py", line 453, in begin
    version, status, reason = self._read_status()
  File "C:\Python27\lib\httplib.py", line 409, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "C:\Python27\lib\socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "C:\Python27\lib\ssl.py", line 734, in recv
    return self.read(buflen)
  File "C:\Python27\lib\ssl.py", line 621, in read
    v = self._sslobj.read(len or 1024)
error: [Errno 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen
```



Discussion:
@Avanatiker @tsnoam will the fix with the exception event influence this?

@Avanatiker  can u specify the version of python telegram bot you're using?
(EDITED the @ user...)

EDITED 2: n/m that, I see that it's a new enough version.

[This link](https://mail.python.org/pipermail/python-list/2015-December/700355.html) suggests we should catch `socket.error`. Any objections?

@jh0ker @Avanatiker 
1. yes, the fix in  revision 560aea5 should have mitigated the problem a bit (in the sense that it would have stopped all the threads cleanly).
2. yes, we should catch `socket.error`. (i'm on it)

Wow that was fast :) my Version: python-telegram-bot (3.4)
Ive fixed the bug by restarting the script: `os.execv(sys.executable, [sys.executable] + sys.argv)` but its just temporary


Resolving patch:
diff --git a/telegram/utils/request.py b/telegram/utils/request.py
--- a/telegram/utils/request.py
+++ b/telegram/utils/request.py
@@ -106,6 +106,9 @@ def decorator(*args, **kwargs):
         except HTTPException as error:
             raise NetworkError('HTTPException: {0!r}'.format(error))
 
+        except socket.error as error:
+            raise NetworkError('socket.error: {0!r}'.format(error))
+
     return decorator
 
 


Test patch: