nickoala / telepot

Python framework for Telegram Bot API
MIT License
2.42k stars 474 forks source link

Can't Connect Through Proxy #410

Open Ahm4dr3za opened 6 years ago

Ahm4dr3za commented 6 years ago

i coded more than 600 line of my group manager bot with this library And it worked very well But a few days, Sometimes It does not work properly

simple code: import telepot

token = '644127962:AAHkQeb1eFmzA-Qt3R2GPlC7nP71VTLoJlY' chat_id = 356346277 telepot.api.set_proxy('http://207.154.208.76:8080/') #http proxy (best ping and work) bot = telepot.Bot(token) bot.sendMessage(chat_id, 'TADA !!!')

output: Traceback (most recent call last): File "C:\Program Files\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\ptvsd_launcher.py", line 111, in vspd.debug(filename, port_num, debug_id, debug_options, run_as) File "C:\Program Files\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd\debugger.py", line 36, in debug run(address, filename, *args, kwargs) File "C:\Program Files\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd_main.py", line 47, in run_file run(argv, addr, kwargs) File "C:\Program Files\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd_main.py", line 98, in _run _pydevd.main() File "C:\Program Files\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd\pydevd\pydevd.py", line 1628, in main globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\Python\Core\Packages\ptvsd\pydevd\pydevd.py", line 1035, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Users\0V3RD05\source\repos\PyBot\PyBot\PyBot.py", line 8, in bot.sendMessage(chat_id, 'TADA !!!') File "C:\Python27\lib\site-packages\telepot__init__.py", line 513, in sendMessage return self._api_request('sendMessage', _rectify(p)) File "C:\Python27\lib\site-packages\telepot__init__.py", line 491, in _api_request return api.request((self._token, method, params, files), *kwargs) File "C:\Python27\lib\site-packages\telepot\api.py", line 154, in request r = fn(args, kwargs) # fn must be thread-safe File "C:\Python27\lib\site-packages\urllib3\request.py", line 150, in request_encode_body return self.urlopen(method, url, extra_kw) File "C:\Python27\lib\site-packages\urllib3\poolmanager.py", line 445, in urlopen return super(ProxyManager, self).urlopen(method, url, redirect=redirect, kw) File "C:\Python27\lib\site-packages\urllib3\poolmanager.py", line 322, in urlopen response = conn.urlopen(method, u.request_uri, kw) File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen response_kw) File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen response_kw) File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen **response_kw) File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "C:\Python27\lib\site-packages\urllib3\util\retry.py", line 398, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot644127962:AAHkQeb1eFmzA-Qt3R2GPlC7nP71VTLoJlY/sendMessage (Caused by SSLError(SSLError('_ssl.c:645: The handshake operation timed out',),))

Python Version: 2.7 What is wrong ? anyone have solution?

Ahm4dr3za commented 6 years ago

Hi @nickoala This is an error that I faced today:

HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot644127962:AAFQIZBX1Qh8QcwryGw0g2Qe58gNid8GB-4/sendMessage (Caused by SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:661)'),))

Is it related to telegram servers ? Every day it just works for a few hours ... but i tested it with VPN and there is no problem ! why?