You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
assignee=Noneclosed_at=<Date2017-11-25.10:39:33.765>created_at=<Date2016-10-01.15:35:54.397>labels= ['3.7', 'type-bug', 'library']
title='netrc does not work if $HOME is not set'updated_at=<Date2017-11-25.10:39:33.763>user='https://github.com/dmerejkowsky'
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.
So if it make sense to run this on Windows*, I would call it a bug.
I am guessing that Windows' FTP clients do not use .netrc.
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.
dmerejkowsky commented on Oct 10, 2016
dmerejkowskymannequin
MannequinAuthor
More actions
if it make sense to run this on Windows
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 ...)
don't know what unix users might reasonbly expect.
Well, I guess as a bonus of this patch we could add a link to the os.path.expanduser section[1] in netrc documentation.
The behavior when $HOME is not set is properly documented there.
FWIW, some history: The $HOME lookup was in Guido's original 1998-12-22 patch:
if not file:
file = os.path.join(os.environ['HOME'], ".netrc")
The lookup was wrapped in try-except 4 years later to give a 'consistent error message'.
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?
dmerejkowsky commented on Oct 18, 2016
dmerejkowskymannequin
MannequinAuthor
More actions
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.
Activity
dmerejkowsky commentedon Oct 1, 2016
If $HOME is not set, netrc will raise an exception.
Attached patch fixes the problem by using
os.path.expanduserinsteadberkerpeksag commentedon Oct 2, 2016
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:
to test the new behavior.
dmerejkowsky commentedon Oct 2, 2016
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!
terryjreedy commentedon Oct 7, 2016
On Windows, HOME is both split into two variables and replaced by USERPROFILE.
C:\Users\Terry>set HOME
HOMEDRIVE=C:
HOMEPATH=\Users\Terry
C:\Users\Terry>set USERPROFILE
USERPROFILE=C:\Users\Terry
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.
dmerejkowsky commentedon Oct 10, 2016
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
os.path.expandusersection[1] innetrcdocumentation.The behavior when $HOME is not set is properly documented there.
[1] https://docs.python.org/3/library/os.path.html#os.path.expanduser
terryjreedy commentedon Oct 10, 2016
FWIW, some history: The $HOME lookup was in Guido's original 1998-12-22 patch:
if not file:
file = os.path.join(os.environ['HOME'], ".netrc")
The lookup was wrapped in try-except 4 years later to give a 'consistent error message'.
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?
dmerejkowsky commentedon Oct 18, 2016
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?
berkerpeksag commentedon Nov 25, 2017
New changeset 8d9bb11 by Berker Peksag in branch 'master':
bpo-28334: netrc() now uses expanduser() to find .netrc file (GH-4537)
8d9bb11
berkerpeksag commentedon Nov 25, 2017
Thanks, Dimitri.