Answer the question
In order to leave comments, you need to log in
How to fix error in telebot in python?
Here is the code:
import telebot
bot = telebot.TeleBot('894562119:AAHq7segxuAgALgaJw4SXeIkOhtIj_AWBC*') # Токен для безопасности исправил
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Привет, ты написал мне /start')
bot.polling()
2019-12-09 18:25:32,195 (util.py:65 PollingThread) ERROR - TeleBot: "ConnectTimeout o
ccurred, args=(MaxRetryError("HTTPSConnectionPool(host='api.telegram.org', port=443):
Max retries exceeded with url: /bot894562119:AAHq7segxuAgALgaJw4SXeIkOhtIj_AWBC8/get
Updates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.Verifi
edHTTPSConnection object at 0x039E5730>, 'Connection to api.telegram.org timed out. (
connect timeout=3.5)'))"),)
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\util\connection.py", line 83, in create_connection
raise err
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\util\connection.py", line 73, in create_connection
sock.connect(sa)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connectionpool.py", line 850, in _validate_conn
conn.connect()
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connection.py", line 284, in connect
conn = self._new_conn()
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connection.py", line 146, in _new_conn
(self.host, self.timeout))
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.VerifiedHTTPSConnection
object at 0x039E5730>, 'Connection to api.telegram.org timed out. (connect timeout=3.
5)')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\req
uests\adapters.py", line 440, in send
timeout=timeout
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\util\retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=4
43): Max retries exceeded with url: /bot894562119:AAHq7segxuAgALgaJw4SXeIkOhtIj_AWBC8
/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.Ve
rifiedHTTPSConnection object at 0x039E5730>, 'Connection to api.telegram.org timed ou
t. (connect timeout=3.5)'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tel
ebot\util.py", line 59, in run
task(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tel
ebot\__init__.py", line 276, in __retrieve_updates
updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tel
ebot\__init__.py", line 246, in get_updates
json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_
updates)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tel
ebot\apihelper.py", line 180, in get_updates
return _make_request(token, method_url, params=payload)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tel
ebot\apihelper.py", line 54, in _make_request
timeout=(connect_timeout, read_timeout), proxies=proxy)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\req
uests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\req
uests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\req
uests\adapters.py", line 496, in send
raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port
=443): Max retries exceeded with url: /bot894562119:AAHq7segxuAgALgaJw4SXeIkOhtIj_AWB
C8/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.
VerifiedHTTPSConnection object at 0x039E5730>, 'Connection to api.telegram.org timed
out. (connect timeout=3.5)'))
"
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\util\connection.py", line 83, in create_connection
raise err
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\url
lib3\util\connection.py", line 73, in create_connection
sock.connect(sa)
socket.timeout: timed out
Answer the question
In order to leave comments, you need to log in
Since telegram is "blocked" in Russia, api will give this error.
Install a VPN on your PC, change the country, then you can start the bot.
Install windscribe. They give 10 gigs for free. Enough for a long time if the traffic is only in Telegram.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question