os.environ['HOSTNAME'] is not set on some OS X installs; use socket.gethostbyname() instead.