[Python] How to deploy TG-bot to PythonAnywhere?

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    When i'm trying to run the bot uploaded to home/%User_name%/ at PythonAnywhere it crashes with:

    File "/home/%User_name%/%Project_name%/./handlers/command_handlers.py",
    line 103, in handle_start
    if str(user_id) in config["ADMINS"]:
    KeyError: 'ADMINS'


    Looks like it can't find my config.json. I have config and data_user JSONs in my home/%User_name%/%Project_name%/ folder. It seems I need to do smth more, than just simply upload my project from PC.

    I have this part of code, related to the path:

    CONFIG_FILE = "%Project_name%/config.json"
    def load_config():
    if not os.path.exists(CONFIG_FILE):
    return {}
    with open(CONFIG_FILE, 'r', encoding='utf-8') as file:
    return json.load(file)


    It worked perfectly on my Win10 PC, where project folder lies right in the Visual Studio Code workspace.

    What should I change to run the bot at PythonAnywhere?

    I tried to change the path in my bot code, but it didn't work.

    Continue reading...

Compartilhe esta Página