'bot.polling() issue with pytelegramapi
I was just doing a simple lines of code and it gives a lot of issues just for using bot.polling().
import telebot
token = '19*******:********-********-lmY'
bot = telebot.TeleBot(token)
@bot.message_handler(commands=['greet'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
bot.polling()
Solution 1:[1]
First
pip uninstall telebot
Then
pip install pyTelegramBotAPI
import telebot
API_KEYS = "API TOKEN"
bot = telebot.TeleBot(API_KEYS)
@bot.message_handler(commands=['greet'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
bot.polling()
Solution 2:[2]
This is likely happening because your environment variable for the API keys is unset:
API_KEYS = os.getenv('API_KEYS')
bot = telebot.TeleBot(API_KEYS)
If the environment variable for 'API_KEYS' is unset, os.getenv will return None. To fix this, make sure the environment variable is set correctly.
To identify this problem more easily in future, you should add key validation to provide a more meaningful error:
try:
API_KEYS = os.environ['API_KEYS']
except KeyError as error:
raise ValueError("API keys are missing.") from err
bot = telebot.TeleBot(API_KEYS)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Piero |
| Solution 2 | thesketh |
