I'm a full beginner at Python. I have a small script that successfully runs on my own PC but when I try to run in on pythonanywhere.com I have these errors:
P.S. I already installed the required pip module
pyrogram
. Also don't pay attention at the first line it isn't necessary: "TgCrypto is missing! Pyrogram will work the same, but at a much slower speed. More info"
same error. when run through the bash command line, everything works fine on your service, the full path is registered using pathlib. But I just can’t run this code through Tasks, it gives a bunch of errors and everything is connected in files (.db, .py) that are in other packages/folders.
https://github.com/ArtDmSav/TG_estate_bot_CY
@fjl When i create and start Always-on tasks :
python3.10 /home/artdmsav/estate_bot/bot_aiogram.py
I have this:
2023-08
-21 10:43:29 - Task preparing to start
Aug 21 10:44:20 Traceback (most recent call last):
Aug 21 10:44:20 File "/home/artdmsav/estate_bot/bot_aiogram.py", line 27, in <module>
Aug 21 10:44:20 token = config['Telegram']['bot_token']
Aug 21 10:44:20 File "/usr/local/lib/python3.10/configparser.py", line 964, in __getitem__
Aug 21 10:44:20 raise KeyError(key)
Aug 21 10:44:20 KeyError: 'Telegram'
and this good work with bash console
@fjl I am using absolute path. Correct me if I'm wrong.
The code that you posted above would not be an absolute path -- that, I think, is what was causing the issue. The cwd function returns the process's current working directory, so putting it at the start of a path is equivalent to using a relative path. If you want to construct a path that is relative to the file where the code appears, you'd need to use this:
dir_path=Path(os.path.dirname(__file__))
Sorry, we have had to rate-limit your feedback sending. Please try again in a few moments...
Thanks for the feedback! Our tireless devs will get back to you soon.