New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
netrc does not work if $HOME is not set #72521
Comments
If $HOME is not set, netrc will raise an exception. Attached patch fixes the problem by using |
Thanks for the patch, Dimitri. I think this is a reasonable improvement. However, since we are changing the behavior of the netrc() class, I'm not sure this can be considered as a bug fix. In any case, 3.3 and 3.4 are in security-fix-only mode so I'm going to remove them from the versions field. We need two things from you to move this forward:
env = support.EnvironmentVarGuard()
env.unset('HOME') to test the new behavior.
|
I was not sure either. The patch does change behavior in subtle ways... I've added a new patch, and sent the CLA form. Thanks for your time! |
On Windows, HOME is both split into two variables and replaced by USERPROFILE. C:\Users\Terry>set USERPROFILE So if it make sense to run this on Windows*, I would call it a bug.
The doc says "the file .netrc in the user’s home directory will be read." without qualification by "if $HOME is set". I don't remember how os.path.expanduser might otherwise find the home directory on unix and don't know what unix users might reasonbly expect. |
I found this issue while running cross-platform code. I needed to store some credentials, did not mind having them in plain-text and I thought .netrc was a good place for this. (did not need to re-invent the wheel ...)
Well, I guess as a bonus of this patch we could add a link to the The behavior when $HOME is not set is properly documented there. [1] https://docs.python.org/3/library/os.path.html#os.path.expanduser |
FWIW, some history: The $HOME lookup was in Guido's original 1998-12-22 patch: Module ntpath dates back to 1994. Expanduser only used HOMEDRIVE and HOMEPATH. Guido added support for HOME in 1997. Support for USERPROFILE was added a decade later. Since the module is NOT marked 'Unix-only', I think it a bug to not use os.path.expanduser. Larry, Ned, do either of you have an opinion on whether the change should be made in current versions or only 3.7? |
During review SilentGhost suggested that maybe a test was not essential. In any case, I think patching documentation about the new behavior won't hurt. Do you want me to do that? |
Thanks, Dimitri. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: