0

i started learning new stuff about programming a bot in Telegram so i wrote my first lines, but when it comes to giving it a try i keep getting some errors so here is my code and the erros i keep getting ...

import telebot , config , os

API_KEY = os.getenv("API_KEY")
bot = telebot.TeleBot(API_KEY)

@bot.message_handler(commands=['Greet'])

def greet(message):
    bot.reply_to(message,"Hey, how's it going?")


bot.polling()

after i run it i get this :

Traceback (most recent call last):
  File "C:\Users\raccoon\Desktop\Coding room\Python 3.9\TelegramBot\main.py", line 12, in <module>
    bot.polling()
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 496, in polling
    self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout)
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 555, in __threaded_polling
    raise e
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 517, in __threaded_polling
    polling_thread.raise_exceptions()
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 87, in raise_exceptions
    raise self.exception_info
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\util.py", line 69, in run
    task(*args, **kwargs)
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 322, in __retrieve_updates
    updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout, long_polling_timeout = long_polling_timeout)
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\__init__.py", line 292, in get_updates
    json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates, long_polling_timeout)
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\apihelper.py", line 281, in get_updates
    return _make_request(token, method_url, params=payload)
  File "C:\Users\raccoon\AppData\Local\Programs\Python\Python39\lib\site-packages\telebot\apihelper.py", line 76, in _make_request
    logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files).replace(token, token.split(':')[0] + ":{TOKEN}"))
AttributeError: 'NoneType' object has no attribute 'split'
[Finished in 1.3s]

i literally have no idea how to get through this, please if someone could help!

1
  • 3
    it seems you don't get API_KEY but None. Try to use value directly in code instead o getting it from environment. Commented May 10, 2021 at 21:56

2 Answers 2

2

From what I can see from the error seems like you API_TOKEN is not on the environment of your computer.

You have two (?) options:

  1. Add the API_TOKEN in yor environment, in the case of windows this can be done using set API_TOKEN your_api_key or export API_TOKEN=your_api_key on Linux

  2. Change your code harcoding the API_KEY directly

API_KEY = your_api_key
bot = telebot.TeleBot(API_KEY)
Sign up to request clarification or add additional context in comments.

Comments

0

you need to load your environment variables first from .env file in the root directory of your project, use python-dotenv.

import os
from dotenv import load_dotenv

load_dotenv()
API_KEY = os.getenv("API_KEY")

this should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.