From 9920d2700ecc76500795cb665fbdc167bef06db1 Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Thu, 27 Dec 2012 17:32:11 +0100 Subject: [PATCH] [FIX] auth_openid: win32: fix ImportError when trying to get system username bzr revid: xal@openerp.com-20121227163211-301w0gus2dx40b3w --- addons/auth_openid/controllers/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/addons/auth_openid/controllers/main.py b/addons/auth_openid/controllers/main.py index be59b9ae5b5..1fcc34c82a0 100644 --- a/addons/auth_openid/controllers/main.py +++ b/addons/auth_openid/controllers/main.py @@ -46,7 +46,18 @@ oidutil.log = _logger.debug def get_system_user(): """Return system user info string, such as USERNAME-EUID""" - info = getpass.getuser() + try: + info = getpass.getuser() + except ImportError: + if os.name == 'nt': + # when there is no 'USERNAME' in environment, getpass.getuser() + # fail when trying to import 'pwd' module - which is unix only. + # In that case we have to fallback to real win32 API. + import win32api + info = win32api.GetUserName() + else: + raise + euid = getattr(os, 'geteuid', None) # Non available on some platforms if euid is not None: info = '%s-%d' % (info, euid())