This turned out to be a problem with the way Windows 7 expands (or in this case, fails to expand) nested environment variables.
kilnauth.py, the following line is used to determine the location of the
_hgcookies directory which stores the kilnauth data:
cookie_path = os.path.expanduser('~\\_hgcookies')
The Python documentation states that:
On Windows [os.path.expanduser], HOME
and USERPROFILE will be used if set,
otherwise a combination of HOMEPATH
and HOMEDRIVE will be used. An initial
~user is handled by stripping the last
directory component from the created
user path derived above.
On the problem computer,
HOME=%HOMEDRIVE%%HOMEPATH%. In the
kilnauth.py line shown above, this should expand out to
HOME=C:\Users\<username>, but this did not happen. Instead, the nested environment variables were not expanded. This resulted in an invalid path for
Once the invalid path is stored, kilnauth.py then runs:
which results in the error shown in the problem statement.
It is not clear why the nested environment variables are not expanded properly. However there is a workaround. On the problem computer, we set
HOME=C:\Users\<username> directly rather than using
After a reboot, this solved the problem.
NOTE: There are several other places in the Mercurial source code where this same pattern is used to determine the user's home path. So even if
kilnauth.py was changed to be more paranoid about finding the home path, there would likely still be other problems.