Fix: OAuth token save crashes on Windows (os.fchmod is Unix-only)#147
Open
SENTMarketing wants to merge 1 commit into
Open
Fix: OAuth token save crashes on Windows (os.fchmod is Unix-only)#147SENTMarketing wants to merge 1 commit into
SENTMarketing wants to merge 1 commit into
Conversation
_save_oauth_token() calls os.fchmod, which does not exist on Windows and raises AttributeError (not OSError), so the except OSError does not catch it. Result: the token file is created empty and --auth fails on Windows. Guard with hasattr(os, "fchmod") so non-POSIX platforms skip it and the write proceeds; POSIX behaviour is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_save_oauth_token()inscripts/google_auth.pycallsos.fchmod(fd, 0o600). On Windowsos.fchmoddoes not exist, so the call raisesAttributeError— which is not caught by the surroundingexcept OSError. The exception propagates beforeos.fdopen(...).write()runs, leaving an emptyoauth-token.jsonand making--authfail on Windows.Observed error during
google_auth.py --auth:(token file ends up empty; refresh/login broken on Windows.)
Fix
Guard the call with
hasattr(os, "fchmod")so non-POSIX platforms simply skip it and proceed to write the token. POSIX behaviour is unchanged (fchmod still enforces 0o600), and_chmod_quiet()already set 0o600 on the file beforehand.Verified:
--authnow writes a valid token with refresh_token on Windows 11 (Python 3.12); unchanged on POSIX.