A couple of points. I don't know why your command failed, but guess you have not logged in (i.e. connect using p4.connect()
). I have tried the following and found it working:
import getpass
import P4
def get_user(user):
"""
Get information for a single user
Return None if not found, or a dict similar to this one:
{
'Update': '1422308004',
'Access': '1515088079',
'User': 'abc',
'FullName': 'Anna Bell Clark',
'Type': 'standard',
'Email': 'abc@example.com'
}
"""
p4 = P4.P4()
p4.password = getpass.getpass()
p4.connect()
try:
users_info = p4.run('users', user)
return users_info[0]
except P4.P4Exception:
return None
user = 'abc'
print(get_user(user))
Notes
- use
getpass.getpass()
to prompt for the password from console. getpass
does not echo the password, so it is reasonably safe to keep your password hidden.