0

Решил научиться писать телеграм бота на Python'е. Нашел статью на хабре на тему написания ботов для начинающих. Скопировал код и вставил в Pycharm. Все библиотеки подключены, но все равно выдает ошибку. Вот код:

import telebot

bot = telebot.TeleBot('<ТОКЕН>') # здесь я не забываю вставлять токен моего бота


@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет, ты написал мне /start')


bot.polling(none_stop=True, interval=0)

А ошибка огромная:

2019-10-27 11:05:28,211 (util.py:65 PollingThread) ERROR - TeleBot: "ConnectTimeout occurred, args=(MaxRetryError("HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot980586311:AAGkPbroLZ1RuE-Bk0TIybIZmGdK5nMqBUE/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))"),) Traceback (most recent call last): File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 157, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection raise err File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\connection.py", line 74, 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\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 672, in urlopen chunked=chunked, File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request self._validate_conn(conn) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn conn.connect() File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 334, in connect conn = self._new_conn() File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 164, in _new_conn % (self.host, self.timeout), urllib3.exceptions.ConnectTimeoutError: (, '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\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send timeout=timeout File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 720, in urlopen method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 436, 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: /bot980586311:AAGkPbroLZ1RuE-Bk0TIybIZmGdK5nMqBUE/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(, '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\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 59, in run task(*args, **kwargs) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot__init__.py", line 276, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot__init.py", line 246, in get_updates json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\apihelper.py", line 180, in get_updates return _make_request(token, method_url, params=payload) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\apihelper.py", line 54, in _make_request timeout=(connect_timeout, read_timeout), proxies=proxy) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 504, in send raise ConnectTimeout(e, request=request) requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot980586311:AAGkPbroLZ1RuE-Bk0TIybIZmGdK5nMqBUE/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(, 'Connection to api.telegram.org timed out. (connect timeout=3.5)')) " Traceback (most recent call last): File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 157, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection raise err File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\connection.py", line 74, 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\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 672, in urlopen chunked=chunked, File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request self._validate_conn(conn) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn conn.connect() File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 334, in connect conn = self._new_conn() File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 164, in _new_conn % (self.host, self.timeout), urllib3.exceptions.ConnectTimeoutError: (, '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\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send timeout=timeout File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 720, in urlopen method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 436, 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: /bot980586311:AAGkPbroLZ1RuE-Bk0TIybIZmGdK5nMqBUE/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(, '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/arkel/PycharmProjects/Телеграм-боты/init.py", line 11, in bot.polling(none_stop=True, interval=0) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot__init__.py", line 389, in polling self.threaded_polling(none_stop, interval, timeout) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot__init.py", line 412, in threaded_polling polling_thread.raise_exceptions() File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 78, in raise_exceptions six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2]) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\six.py", line 693, in reraise raise value File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 59, in run task(*args, **kwargs) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot__init.py", line 276, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot__init.py", line 246, in get_updates json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\apihelper.py", line 180, in get_updates return _make_request(token, method_url, params=payload) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\apihelper.py", line 54, in _make_request timeout=(connect_timeout, read_timeout), proxies=proxy) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "C:\Users\arkel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 504, in send raise ConnectTimeout(e, request=request) requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot980586311:AAGkPbroLZ1RuE-Bk0TIybIZmGdK5nMqBUE/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))

Искал в инете ответ на этот вопрос, но так как не нашел, решил написать сюда

надеюсь на ответ

3
  • 1
    Что помешало прочитать текст ошибки? Это одна и та же ошибка, случившаяся несколько раз. Нет соединения с сервером. Commented 27 окт. 2019 в 8:48
  • Telegram заблокирован на территории РФ. Не забывайте об этом. Вам следует использовать proxy.
    – nomnoms12
    Commented 27 окт. 2019 в 11:05
  • 1
    Если Вы совсем новичок, то самым простым решением для Вас будет использование бесплатного VPN. Скачайте программу, запустите VPN, попробуйте повторить запуск кода.
    – fer0m
    Commented 28 окт. 2019 в 12:13

0

Ваш ответ

Нажимая «Отправить ответ», вы соглашаетесь с условиями пользования и подтверждаете, что прочитали политику конфиденциальности.

Посмотрите другие вопросы с метками или задайте свой вопрос.