withings-sync icon indicating copy to clipboard operation
withings-sync copied to clipboard

Token requests when running as a Windows Task

Open dnbrv opened this issue 10 months ago • 5 comments

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?

dnbrv avatar Apr 05 '24 12:04 dnbrv

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?

longstone avatar Apr 23 '24 12:04 longstone

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.

dnbrv avatar Apr 30 '24 02:04 dnbrv

@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.

harupong avatar May 07 '24 04:05 harupong

@harupong That worked! Thank you!

dnbrv avatar May 07 '24 23:05 dnbrv

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

dnbrv avatar May 08 '24 00:05 dnbrv

@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?

longstone avatar Jul 01 '24 16:07 longstone

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

dnbrv avatar Jul 29 '24 15:07 dnbrv