0

I can't work out what I'm doing wrong here. I want to set up a new user if this class is instantiated and there is no user already pickled. My __init__ method currently looks like this:

class User:
    def __init__(self, *args, **kwargs):
        if os.path.isfile(f"{get_cwd()}/user.pickle"):
            self.load_user()
        else:
            self.email_address = input("What's your email address?: ")
            self.email_password = base64.b64encode(getpass("What's your email password?: ").encode("utf-8"))
            self.save_user()

However, when I instantiate the class, it doesn't get past asking for self.email_address. If I change the self.email_password to a simple input function it works. What am I doing wrong with using getpass() here?

I've tried making a separate function to receive / encode the password variable and calling that from within the __init__ method but it does the same thing.

If I make the whole script functional if works (but it's a little lengthy!)

Why am I having problems with getpass and a class-based approach??

EDIT: was trying to run through PyCharm terminal and the above is more or less irrelevant.

nihilok
  • 1,325
  • 8
  • 12
  • 1
    `getpass` depends on the environment it's using. How are you running this code? Are you using PyCharm? Does running it in a terminal make a difference? – Alex Hall Jan 01 '21 at 11:01
  • damn! I even knew that already! yes, that is the issue. I don't even need to test it, I've had the same problem before lol! thank you! I will remember this now! – nihilok Jan 01 '21 at 11:05
  • 1
    You can edit the run configuration and tick "Emulate terminal in output console" to fix it in pycharm – Alex Hall Jan 01 '21 at 11:37

1 Answers1

0

Thank you to @Alex Hall for reminding me that getpass doesn't work through the PyCharm terminal. Works perfectly fine in a normal terminal.

nihilok
  • 1,325
  • 8
  • 12