Automatically format inputs to be valid usernames

Also fix bug in CLI that caused AttributeError when an error
response is returned