Твой Профессор
Мастер
(1546)
1 месяц назад
Интернет точно есть?
ВПН не используешь? Брандмауэр не блокирует api.telegram.оrg?
Токен точно правильный?
Добавь лучше параметр timeout в метод infinity_polling, чтобы избежать зависания при проблемах с сетью: bot.infinity_polling(timeout=10)
Добавьте обработку исключений для случаев, когда сеть недоступна. Например:
import time
import telebot
from requests.exceptions import ConnectionError
bot = telebot.TeleBot("7935813107:AAGdqDdUHfhNZsbVVfQK4oPCxLCySwio3tI")
@bot.message_handler(commands=['start', 'hello'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
@bot.message_handler(func=lambda msg: True)
def echo_all(message):
bot.reply_to(message, message.text)
while True:
try:
bot.infinity_polling(timeout=10)
except ConnectionError as e:
print(f"Connection error: {e}. Retrying in 10 seconds...")
time.sleep(10)
except Exception as e:
print(f"Unexpected error: {e}. Retrying in 10 seconds...")
time.sleep(10)
Глянь, чтоб была установлена последняя версия библиотеки. Обнови её, если необходимо: pip install --upgrade pyTelegramBotAPI
Если проблема сохраняется, попробуй использовать библиотеку aiogram вместо pyTelegramBotAPI. Она более современная
2025-01-01 16:36:49,916 (__init__.py:1117 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/connection.py", line 198, in _new_conn
sock = connection.create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/util/connection.py", line 85, in create_connection
raise err
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
OSError: [Errno 101] Network is unreachable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/connectionpool.py", line 488, in _make_request
raise new_e
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/connectionpool.py", line 464, in _make_request
self._validate_conn(conn)
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1093, in _validate_conn
conn.connect()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/connection.py", line 704, in connect
self.sock = sock = self._new_conn()
^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/urllib3/connection.py", line 213, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7425d39510>: Failed to establish a new connection: [Errno 101] Network is unreachable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/requests/adapters.py", line 667, in send
resp = conn.urlopen(
^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/не смог написать до конца но как исправить пж
import telebot
# Replace with your bot token you get from BotFather on telegram
bot = telebot.TeleBot("7935813107:AAGdqDdUHfhNZsbVVfQK4oPCxLCySwio3tI")
@bot.message_handler(commands=['start', 'hello'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
@bot.message_handler(func=lambda msg: True) # handles all other message
def echo_all(message):
bot.reply_to(message, message.text)
bot.infinity_polling()
"