jaroslawhartman / withings-sync

Synchronisation of Withings weight
MIT License
455 stars 89 forks source link

Token requests when running as a Windows Task #167

Closed dnbrv closed 3 months ago

dnbrv commented 7 months ago

I wrote a Batch script to sync once a day with a variable date parameter. When the script is executed manually, everything works fine. But when I run it from Windows Task Scheduler whether on schedule or on demand, I receive the error Can't read config file ./.withings_user.json and the prompt to get the token from Withings. The error re-occurs on the next run after providing an updated token.

I thought the issue was that the task was being executed under a different user and doesn't have access to %appdata%\Python\Python312\site-packages\withings_sync, but task properties are set to run under my account. What could be the issue?

longstone commented 7 months ago

I assume the issue ist resolving the home dir:

HOME = os.environ.get("HOME", ".") https://github.com/jaroslawhartman/withings-sync/blob/master/withings_sync/withings2.py#L12

and

USER_CONFIG = os.environ.get("WITHINGS_USER", HOME + "/.withings_user.json") https://github.com/jaroslawhartman/withings-sync/blob/master/withings_sync/withings2.py#L21

Can you try set HOME?

dnbrv commented 6 months ago

I'm sorry for the dumbest question. My coding skills are only as good as using precise instructions and asking ChatGPT to debug.

Where should I set HOME environmental variable? Will it be on Windows level? I tried this documentation for os.environ and the output list didn't have a HOME variable.

harupong commented 6 months ago

@dnbrv You use GUI to set environmental variables in Windows. ref. https://www.computerhope.com/issues/ch000549.htm

Instead of modifying "Path", try creating new user variable "HOME", and set the value of it to the address of the directory that .withings_user.json is located.

dnbrv commented 6 months ago

@harupong That worked! Thank you!

dnbrv commented 6 months ago

@harupong Nope. It worked when I set it up. The next time it triggered automatically, the token prompt came up again.

longstone commented 4 months ago

@harupong Nope. It worked when I set it up. The next time it triggered automatically, the token prompt came up again.

can you run set in this scope, to ensure HOME is still configured?

dnbrv commented 3 months ago

@longstone Strangely, it has resolved itself and everything has been working fine for 2 months now.