сделал простово телеграм бота в теле не работает а в кмд выдает большую ошибку токен присутствует

errorsad

Новичок
Пользователь
Апр 10, 2020
25
3
3
Python:
import telebot

fox = telebot.TeleBot("токен")
keyboard1 = telebot.types.ReplyKeyboardMarkup()
keyboard1.row("нагенцы","пица",)

@fox.message_handler(commands=["starts"])
def fer(message):
    fox.fer(message.chat.id , "ресторан бот начинает работу", reply_markup=keyboard1)

@fox.message_handler(content_types=['text'])
def ere_van(message):
    if message.text.lower() == "нагенцы":
         bot.send_message(message.chat.id, 'цена 200руб')
    elif message.text.lower() == "пица":
         bot.send_message(message.chat.id, 'пица стоит  500руб')

fox.polling()
python 3.8.2
windows 7
 

BPRO

Пользователь
Пользователь
Апр 22, 2020
12
8
3
Здравствуйте! Вы забыли указать параметр none_stop=True в методе polling()

Рабочий код будет таким:
import telebot

fox = telebot.TeleBot("токен")
keyboard1 = telebot.types.ReplyKeyboardMarkup()
keyboard1.row("нагенцы","пица",)

@fox.message_handler(commands=["starts"])
def fer(message):
fox.fer(message.chat.id , "ресторан бот начинает работу", reply_markup=keyboard1)

@fox.message_handler(content_types=['text'])
def ere_van(message):
if message.text.lower() == "нагенцы":
bot.send_message(message.chat.id, 'цена 200руб')
elif message.text.lower() == "пица":
bot.send_message(message.chat.id, 'пица стоит 500руб')

fox.polling(none_stop=True)


И да, многие новички вместо того чтобы установить библиотеку pytelegrambotapi устанавливает telebot. В вашем коде нужна библиотека pytelegrambotapi
 

Rud356

Модератор
Команда форума
Модератор
Апр 5, 2020
44
21
8
Какую конкретно ошибку выдает? А то сейчас это будет тыканье пальцем в небо.
 

errorsad

Новичок
Пользователь
Апр 10, 2020
25
3
3
2020-04-22 18:52:40,176 (util.py:66 PollingThread) ERROR - TeleBot: "ConnectTimeout occurred, args=(MaxRetryError("HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot1116796875:AAEe3bDVbgoW3qXvEvty1HCGK86FT-Q9aBc/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x03384E38>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))"),)
Traceback (most recent call last):
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-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\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 976, in _validate_conn
conn.connect()
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 308, in connect
conn = self._new_conn()
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 164, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x03384E38>, '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\Python38-32\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 724, in urlopen
retries = retries.increment(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 439, 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: /bot1116796875:AAEe3bDVbgoW3qXvEvty1HCGK86FT-Q9aBc/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x03384E38>, '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\Python38-32\lib\site-packages\telebot\util.py", line 60, in run
task(*args, **kwargs)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 279, in __retrieve_updates
updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 249, in get_updates
json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 194, in get_updates
return _make_request(token, method_url, params=payload)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 57, in _make_request
result = _get_req_session().request(method, request_url, params=params, files=files,
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-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: /bot1116796875:AAEe3bDVbgoW3qXvEvty1HCGK86FT-Q9aBc/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x03384E38>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))
"
Traceback (most recent call last):
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\connection.py", line 84, in create_connection
raise err
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-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\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 976, in _validate_conn
conn.connect()
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 308, in connect
conn = self._new_conn()
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 164, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x03384E38>, '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\Python38-32\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 724, in urlopen
retries = retries.increment(
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 439, 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: /bot1116796875:AAEe3bDVbgoW3qXvEvty1HCGK86FT-Q9aBc/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x03384E38>, '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:\Python\фигня.py", line 19, in <module>
fox.polling()
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 392, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 415, in __threaded_polling
polling_thread.raise_exceptions()
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 79, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\six.py", line 703, in reraise
raise value
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 60, in run
task(*args, **kwargs)
 

errorsad

Новичок
Пользователь
Апр 10, 2020
25
3
3
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 279, in __retrieve_updates
updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 249, in get_updates
json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 194, in get_updates
return _make_request(token, method_url, params=payload)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 57, in _make_request
result = _get_req_session().request(method, request_url, params=params, files=files,
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "C:\Users\денис.User-ПК\AppData\Local\Programs\Python\Python38-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: /bot1116796875:AAEe3bDVbgoW3qXvEvty1HCGK86FT-Q9aBc/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x03384E38>, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))
 

errorsad

Новичок
Пользователь
Апр 10, 2020
25
3
3
фух вот вся
 

BPRO

Пользователь
Пользователь
Апр 22, 2020
12
8
3
Вы случайно не из РФ?
 

errorsad

Новичок
Пользователь
Апр 10, 2020
25
3
3
Нет я из РФ просто я сейчас нахожусь не совсем у себя дома и мне печать не удобно!
 

BPRO

Пользователь
Пользователь
Апр 22, 2020
12
8
3
Нет я из РФ просто я сейчас нахожусь не совсем у себя дома и мне печать не удобно!
В любом случае ошибка говорит что оно не может подключиться к серверам телеграмма, попробуйте подключиться через прокси или воспользуйтесь VPN

И да, пере-выпустите токен(вы его уже спалили)
 

errorsad

Новичок
Пользователь
Апр 10, 2020
25
3
3
VPN надо поставить на какую страну?
 

BPRO

Пользователь
Пользователь
Апр 22, 2020
12
8
3
VPN надо поставить на какую страну?
Куда не дотягивает рука РКН
 

Форум IT Специалистов