This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author acdha
Recipients acdha
Date 2014-01-07.16:15:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is a more general version of #10496: os.path.expanduser is documented as returning the unmodified string if it cannot be expanded ( but there's one edge case where this can fail: when running without HOME in the environment:

In this case, pwd.getpwuid is called and although it's not documented as such, it raises a KeyError anytime the underlying POSIX getpwuid() call fails:

Reproducing this deliberately:

cadams@Io:~ $ sudo -H python
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import posix
>>> posix.setuid(1001)
>>> posix.seteuid(1001)
>>> os.environ.pop('HOME')
>>> os.path.expanduser("~")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 269, in expanduser
    userhome = pwd.getpwuid(os.getuid()).pw_dir
KeyError: 'getpwuid(): uid not found: 1001'

Date User Action Args
2014-01-07 16:15:27acdhasetrecipients: + acdha
2014-01-07 16:15:27acdhasetmessageid: <>
2014-01-07 16:15:27acdhalinkissue20164 messages
2014-01-07 16:15:26acdhacreate