Здравствуйте! Бот отлично работает на локальном хосте, но как только пробую поставить на heroku/pythonanywhere вылетает ошибка:
Traceback (most recent call last):
File "/home/Jammer12/airdrop/bot.py", line 26, in
BOT_TOKEN = os.environ["BOT_TOKEN"]
File "/usr/local/lib/python3.9/os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'BOT_TOKEN'
Отрезок кода, где нужно исправить ошибку:
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update, InlineKeyboardMarkup
from bson.json_util import dumps
from multicolorcaptcha import CaptchaGenerator
from jokes import getJoke
from telegram.ext import (
Updater,
CommandHandler,
MessageHandler,
Filters,
ConversationHandler,
CallbackContext,
PicklePersistence,
)
from telegram.utils import helpers
import telegram
import pymongo
import logging
import os
import pickle
# from dotenv import load_dotenv
# load_dotenv()
USERINFO = {} # holds user information
CAPTCHA_DATA = {}
# %% ENV VARIABLES
BOT_TOKEN = os.environ["BOT_TOKEN"]
DB_URI = os.environ["DB_URI"]
ADMIN_USERNAME = os.environ["ADMIN_USERNAME"]
TWITTER_LINKS = os.environ["TWITTER_LINKS"]
TELEGRAM_LINKS = os.environ["TELEGRAM_LINKS"]
DISCORD_LINKS = os.environ["DISCORD_LINKS"]
MAX_USERS = int(os.environ["MAX_USERS"])
MAX_REFS = int(os.environ["MAX_REFS"])
CAPTCHA_ENABLED = os.environ["CAPTCHA_ENABLED"]
TWITTER_LINKS = TWITTER_LINKS.split(",")
TELEGRAM_LINKS = TELEGRAM_LINKS.split(",")
DISCORD_LINKS = DISCORD_LINKS.split(",")
TWITTER_LINKS = "\n".join(TWITTER_LINKS)
TELEGRAM_LINKS = "\n".join(TELEGRAM_LINKS)
DISCORD_LINKS = "\n".join(DISCORD_LINKS)
STATUS_PATH = "./conversationbot/botconfig.p"
if os.path.exists(STATUS_PATH):
BOT_STATUS = {}
pickle.load(open(STATUS_PATH, "rb"))
else:
BOT_STATUS = {"status": "ON"}
# %% MONGODB CONNECTION
CONNECTION_STRING = os.environ.get("DB_URI")
myclient = pymongo.MongoClient(CONNECTION_STRING)
mydb = myclient["airdrop"]
users = mydb["users"]
users.create_index([('ref', pymongo.TEXT)], name='search_index', default_language='english')
users.create_index("userId")
# %% Setting up things
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
print(BOT_TOKEN)
persistence = PicklePersistence(filename='conversationbot/conversationbot')
updater = Updater(token=BOT_TOKEN, use_context=True, persistence=persistence)
dispatcher = updater.dispatcher
И настройки в env:
ADMIN_USERNAME = Jaammerr
BOT_TOKEN = 5137515128*************
TELEGRAM_LINKS =
https://t.me/a**********,
https://t.me/+Rsy**********,https://t.me/+M********
TWITTER_LINKS =
https://twitter.com/an*******
DISCORD_LINKS =
https://discord.gg/yY********
MAX_USERS = 10000
MAX_REFS = 100
CAPTCHA_ENABLED = YES
DB_URI = mongodb+
srv://*****************@cluster0.xasb0.mongodb.net...