PythonAnywhere Forums

telegram bot socket.timeout: timed out

hi there, my code works very well last night,

but today have problem.

2017-09-11 05:07:12,951: [2017-09-11 05:07:12,947] ERROR in app: Exception on /110379909005 [POST] 
2017-09-11 05:07:12,951: Traceback (most recent call last):
2017-09-11 05:07:12,951:   File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 589, in urlopen
2017-09-11 05:07:12,951:     self._prepare_proxy(conn)
2017-09-11 05:07:12,951:   File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 797, in _prepare_proxy
2017-09-11 05:07:12,952:     conn.connect()
2017-09-11 05:07:12,952:   File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line 267, in connect
2017-09-11 05:07:12,952:     self._tunnel()
2017-09-11 05:07:12,952:   File "/usr/lib/python3.5/http/client.py", line 827, in _tunnel
2017-09-11 05:07:12,952:     (version, code, message) = response._read_status()
2017-09-11 05:07:12,952:   File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
2017-09-11 05:07:12,953:     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
2017-09-11 05:07:12,953:   File "/usr/lib/python3.5/socket.py", line 575, in readinto
2017-09-11 05:07:12,953:     return self._sock.recv_into(b)
2017-09-11 05:07:12,953: socket.timeout: timed out
2017-09-11 05:07:12,953: 
2017-09-11 05:07:12,953: During handling of the above exception, another exception occurred:
2017-09-11 05:07:12,954: 
2017-09-11 05:07:12,954: Traceback (most recent call last):
2017-09-11 05:07:12,954:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1988, in wsgi_app
2017-09-11 05:07:12,954:     response = self.full_dispatch_request()
2017-09-11 05:07:12,954:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1641, in full_dispatch_request
2017-09-11 05:07:12,954:     rv = self.handle_user_exception(e)
2017-09-11 05:07:12,954:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1544, in handle_user_exception
2017-09-11 05:07:12,954:     reraise(exc_type, exc_value, tb)
2017-09-11 05:07:12,955:   File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
2017-09-11 05:07:12,955:     raise value
2017-09-11 05:07:12,955:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1639, in full_dispatch_request
2017-09-11 05:07:12,955:     rv = self.dispatch_request()
2017-09-11 05:07:12,955:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1625, in dispatch_request
2017-09-11 05:07:12,955:     return self.view_functions[rule.endpoint](**req.view_args)
2017-09-11 05:07:12,955:   File "/home/as8896/mysite/flask_app.py", line 307, in telegram_webhook
2017-09-11 05:07:12,956:     bot.sendMessage(288115423, user+': '+text)
2017-09-11 05:07:12,956:   File "/home/as8896/.local/lib/python3.5/site-packages/telepot/__init__.py", line 445, in sendMessage
2017-09-11 05:07:12,956:     return self._api_request('sendMessage', _rectify(p))
2017-09-11 05:07:12,956:   File "/home/as8896/.local/lib/python3.5/site-packages/telepot/__init__.py", line 434, in _api_request
2017-09-11 05:07:12,956:     return api.request((self._token, method, params, files), **kwargs)
2017-09-11 05:07:12,956:   File "/home/as8896/.local/lib/python3.5/site-packages/telepot/api.py", line 130, in request
2017-09-11 05:07:12,956:     r = fn(*args, **kwargs)  # `fn` must be thread-safe
2017-09-11 05:07:12,957:   File "/usr/local/lib/python3.5/dist-packages/urllib3/request.py", line 151, in request_encode_body
2017-09-11 05:07:12,957:     return self.urlopen(method, url, **extra_kw)
2017-09-11 05:07:12,957:   File "/usr/local/lib/python3.5/dist-packages/urllib3/poolmanager.py", line 363, in urlopen
2017-09-11 05:07:12,957:     return super(ProxyManager, self).urlopen(method, url, redirect=redirect, **kw)
2017-09-11 05:07:12,957:   File "/usr/local/lib/python3.5/dist-packages/urllib3/poolmanager.py", line 248, in urlopen
2017-09-11 05:07:12,957:     response = conn.urlopen(method, u.request_uri, **kw)
2017-09-11 05:07:12,957:   File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 640, in urlopen
2017-09-11 05:07:12,958:     _stacktrace=sys.exc_info()[2])
2017-09-11 05:07:12,958:   File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 238, in increment
2017-09-11 05:07:12,958:     raise six.reraise(type(error), error, _stacktrace)
2017-09-11 05:07:12,958:   File "/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py", line 685, in reraise
2017-09-11 05:07:12,958:     raise value.with_traceback(tb)
2017-09-11 05:07:12,958:   File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 589, in urlopen
2017-09-11 05:07:12,958:     self._prepare_proxy(conn)
2017-09-11 05:07:12,958:   File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 797, in _prepare_proxy
2017-09-11 05:07:12,959:     conn.connect()
2017-09-11 05:07:12,959:   File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line 267, in connect
2017-09-11 05:07:12,959:     self._tunnel()
2017-09-11 05:07:12,959:   File "/usr/lib/python3.5/http/client.py", line 827, in _tunnel
2017-09-11 05:07:12,959:     (version, code, message) = response._read_status()
2017-09-11 05:07:12,959:   File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
2017-09-11 05:07:12,959:     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
2017-09-11 05:07:12,959:   File "/usr/lib/python3.5/socket.py", line 575, in readinto
2017-09-11 05:07:12,960:     return self._sock.recv_into(b)
2017-09-11 05:07:12,960: urllib3.exceptions.ProxyError: ('Cannot connect to proxy.', timeout('timed out',))
2017-09-11 05:07:12,947: Exception on /110379909005 [POST]#012Traceback (most recent call last):#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 589, in urlopen#012    self._prepare_proxy(conn)#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 797, in _prepare_proxy#012    conn.connect()#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line 267, in connect#012    self._tunnel()#012  File "/usr/lib/python3.5/http/client.py", line 827, in _tunnel#012    (version, code, message) = response._read_status()#012  File "/usr/lib/python3.5/http/client.py", line 258, in _read_status#012    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")#012  File "/usr/lib/python3.5/socket.py", line 575, in readinto#012    return self._sock.recv_into(b)#012socket.timeout: timed out#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1988, in wsgi_app#012    response = self.full_dispatch_request()#012  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1641, in full_dispatch_request#012    rv = self.handle_user_exception(e)#012  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1544, in handle_user_exception#012    reraise(exc_type, exc_value, tb)#012  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise#012    raise value#012  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1639, in full_dispatch_request#012    rv = self.dispatch_request()#012  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1625, in dispatch_request#012    return self.view_functions[rule.endpoint](**req.view_args)#012  File "/home/as8896/mysite/flask_app.py", line 307, in telegram_webhook#012    bot.sendMessage(288115423, user+': '+text)#012  File "/home/as8896/.local/lib/python3.5/site-packages/telepot/__init__.py", line 445, in sendMessage#012    return self._api_request('sendMessage', _rectify(p))#012  File "/home/as8896/.local/lib/python3.5/site-packages/telepot/__init__.py", line 434, in _api_request#012    return api.request((self._token, method, params, files), **kwargs)#012  File "/home/as8896/.local/lib/python3.5/site-packages/telepot/api.py", line 130, in request#012    r = fn(*args, **kwargs)  # `fn` must be thread-safe#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/request.py", line 151, in request_encode_body#012    return self.urlopen(method, url, **extra_kw)#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/poolmanager.py", line 363, in urlopen#012    return super(ProxyManager, self).urlopen(method, url, redirect=redirect, **kw)#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/poolmanager.py", line 248, in urlopen#012    response = conn.urlopen(method, u.request_uri, **kw)#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 640, in urlopen#012    _stacktrace=sys.exc_info()[2])#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 238, in increment#012    raise six.reraise(type(error), error, _stacktrace)#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py", line 685, in reraise#012    raise value.with_traceback(tb)#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 589, in urlopen#012    self._prepare_proxy(conn)#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 797, in _prepare_proxy#012    conn.connect()#012  File "/usr/local/lib/python3.5/dist-packages/urllib3/connection.py", line 267, in connect#012    self._tunnel()#012  File "/usr/lib/python3.5/http/client.py", line 827, in _tunnel#012    (version, code, message) = response._read_status()#012  File "/usr/lib/python3.5/http/client.py", line 258, in _read_status#012    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")#012  File "/usr/lib/python3.5/socket.py", line 575, in readinto#012    return self._sock.recv_into(b)#012urllib3.exceptions.ProxyError: ('Cannot connect to proxy.', timeout('timed out',))

It takes time out, but the traffic graph seems to be similar to usual.

I do not know what the problem is. How can I solve this?

I am not good at English and I am against manners. sorry

The proxy server that handles Internet access for free accounts had a few problems this morning, and has been restarted -- your site should work again now. However, I see you have a paid account -- do you still have code like this:

proxy_url = "http://proxy.server:3128"
telepot.api._pools = {
    'default': urllib3.ProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),
}
telepot.api._onetime_pool_spec = (urllib3.ProxyManager, dict(proxy_url=proxy_url, num_pools=1, maxsize=1, retries=False, timeout=30))

...at the start of your Flask code? If so, you can remove it -- it's only needed for free accounts, and if you remove it you won't depend on the proxy server.

I came to the forums to ask if I could start developing a basic telegram bot with a free account or a $5/month account?

I'm SUPER NEW to python and this thread kind of answers the question, but I'm still going to ask. Thanks all!

Absolutely! We even have a beginner's guide, which shows you how to write one using a free account :-)

Absolutely! We even have a beginner's guide, which shows you how to write one using a free account :-)

Thanks for responding! I'm going to look into this today!!

:-)

:-)

I got the bot working! That's super exciting, but do you have examples of keyboards? Sorry to hijack this thread, but I'm trying to make a bot that can make a button appear for people to acknowledge that they read a displayed message. I figured the best implementation would be an inline keyboard, but I'm having trouble finding examples of it. Are there any examples of this you could point me to that is as friendly as the beginner's guide or similar?

Unfortunately not :-(