klept0 / MS-Rewards-Farmer

A simple bot that uses Selenium to farm M$ Rewards in Python
MIT License
240 stars 49 forks source link

Error when executing script from .bat file #113

Closed iDarkSnow closed 4 months ago

iDarkSnow commented 4 months ago

Before submitting a bug report...

Title

Describe the bug

I have a simple .bat file that does the following:

taskkill /pid chrome.exe /t /f taskkill /pid msedge.exe /t /f

---\AppData\Local\Programs\Python\Python39\python.exe "---\Microsoft Rewards\MS-Rewards-Farmer\main.py" -g IT -l it -v

taskkill /pid chrome.exe /t /f taskkill /pid msedge.exe /t /f

When i execute this script manually from PowerShell it executes without problems.

Copy and paste your error

I created a task in the task scheduler to execute this bat file daily, but when it starts the following happens:

Traceback (most recent call last): File "---\Microsoft Rewards\MS-Rewards-Farmer\main.py", line 316, in main() File "---\Microsoft Rewards\MS-Rewards-Farmer\main.py", line 57, in main Utils.send_notification("⚠️ Error occurred, please check the log", str(e)) File "---\Microsoft Rewards\MS-Rewards-Farmer\src\utils.py", line 38, in send_notification for url in Utils.load_config(config_file)['apprise']['urls']: File "---\Microsoft Rewards\MS-Rewards-Farmer\src\utils.py", line 32, in load_config with open(config_file, 'r') as file: FileNotFoundError: [Errno 2] No such file or directory: 'config.yaml'

Screenshots

Can't provide screenshots as the browser opens and instantly closes

Value of dashboard variable

N/A

cal4 commented 4 months ago

This is happening because the code assumes that the current working directory is the root of the project, where config.yaml exists. If main.py is called from somewhere other than the root of the project, you'll get this error. To confirm for yourself, try executing from a terminal one directory above/below.

So, short term fix is to cd your script to the project dir before running.

Long term fix is to get the config.yaml's absolute path, like this. (I'm planning on merging this stuff after I've run it a few days).

iDarkSnow commented 4 months ago

I did figure it was a path problem and i did try the short term fix already but i still had the same problem. Now, i tried to copy your utils.py file but i get this: Traceback (most recent call last): File "---\Microsoft Rewards\MS-Rewards-Farmer\main.py", line 16, in from src import ( File "---\Microsoft Rewards\MS-Rewards-Farmer\src__init__.py", line 1, in from .browser import Browser File "---\Microsoft Rewards\MS-Rewards-Farmer\src\browser.py", line 12, in from src.utils import Utils File "---\Microsoft Rewards\MS-Rewards-Farmer\src\utils.py", line 26, in class Utils: File "---\Microsoft Rewards\MS-Rewards-Farmer\src\utils.py", line 40, in Utils def loadConfig(config_file=getProjectRoot() / "config.yaml"): TypeError: 'staticmethod' object is not callable

An additional info i forgot. This script was working for a lot of time before some pull i did not so long ago

cal4 commented 4 months ago

It's best to checkout the whole repo. That code depends on other changes which is why you're getting a typeerror.

iDarkSnow commented 4 months ago

For now i fixed it by putting the absolute path of my config.yaml file in the utils.py script, we can close if there is no other solution to this atm

klept0 commented 4 months ago

As @cal4 said in his comment - other changes were also made so it's best to grab all updated files to make sure you are on the most recent version for all changes. Since you have it working with your method I will close this and if a PR request is made for changes we can review and go from there.