Launchpadlib crashes if os.environ['HOME'] not set

Bug #690783 reported by Anthony Lenton
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
launchpadlib
Fix Committed
Low
Martin Packman

Bug Description

If os.environ['HOME'] isn't set, Launchpadlib's login_anonymously fails:

anthony@atenea:~$ unset HOME
anthony@atenea:/home/anthony$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from launchpadlib.launchpad import Launchpad
>>> Launchpad.login_anonymously('some consumer', 'https://launchpad.net/api/1.0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/launchpadlib/launchpad.py", line 225, in login_anonymously
    service_root_dir) = cls._get_paths(service_root, launchpadlib_dir)
  File "/usr/lib/pymodules/python2.6/launchpadlib/launchpad.py", line 319, in _get_paths
    home_dir = os.environ['HOME']
  File "/usr/lib/python2.6/UserDict.py", line 22, in __getitem__
    raise KeyError(key)
KeyError: 'HOME'
>>>

This bites you when deploying in environments that don't ensure os.environ['HOME'] is set, as with Apache + modwsgi.

Related branches

Revision history for this message
Robert Collins (lifeless) wrote :

Hi there, using mod_wsgi or the like is very unsafe - see bug 459418 : we really want single-threaded environments for launchpadlib today. I'd love a concurrent environment or a cacheless variant :)

Changed in launchpadlib:
status: New → Triaged
importance: Undecided → Low
Revision history for this message
Robert Collins (lifeless) wrote :

What you should do is setup a cache per thread, which will workaround this anyhow.

Revision history for this message
Martin Packman (gz) wrote :

Also the case on windows machines which may have HOMEDRIVE and HOMEPATH instead. Without any kind of home, raising an error seems like the right thing, but it should be a useful one that hints at the right fix.

Changed in launchpadlib:
assignee: nobody → Martin [gz] (gz)
Martin Packman (gz)
Changed in launchpadlib:
status: Triaged → In Progress
Martin Packman (gz)
Changed in launchpadlib:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.