admin管理员组文章数量:1296258
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.
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.
Share asked Feb 11 at 21:46 PlemPlem 34 bronze badges 2- Are you using a virtual environment? – dev_light Commented Feb 12 at 3:35
- I'm using simple Files upload and running the bot.py with console. – Plem Commented Feb 12 at 6:53
1 Answer
Reset to default 0Okay, I've tried a bit more and got success.
Both user_data and config files lies in %project_name% folder, where main bot.py file is.
I changed user_data path to simple "DATA_FILE: "user_data.json"
, and edited the code to:
CONFIG_FILE = "config.json" # <- changed here
def load_config():
if not CONFIG_FILE: # <- and here
return {}
with open(CONFIG_FILE, 'r', encoding='utf-8') as file:
return json.load(file)
本文标签: pythonHow to deploy TGbot to PythonAnywhereStack Overflow
版权声明:本文标题:python - How to deploy TG-bot to PythonAnywhere? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741632924a2389470.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论