Search code examples
pythonpoplib

Python poplib error when trying to parse in a string


I am using poplib to get email from the POP3 server.

But this error occurred:

*cmd* 'USER [email protected]'
*put* b'USER [email protected]'
*get* b'+OK send PASS\r\n'
*resp* b'+OK send PASS'
*cmd* 'PASS asdasd\n'
*put* b'PASS asdasd\n'
*get* b'-ERR bad command qj1pf12899100pbb.19\r\n'
*resp* b'-ERR bad command qj1pf12899100pbb.19'

here is the python code:

import getpass, poplib
def LoginGmail( email, pa ):
    M = poplib.POP3_SSL('pop.googlemail.com', '995') 
    M.set_debuglevel(2)
    user = email
    try:
        M.user(user)
        M.pass_(pa)
    except:
        print('Invalid credentials')
    else:
        print('Successful login')

...
in main():
loginGmail('[email protected]','asdasd')

However, in the function, when I try to type in the password (indicate as 'pa') and direct input, it works. It doesnt happen for user.

Please help, i've been trying for a day to figure it out but seem impossible for me :(

Thank you


Solution

  • Found the problem, when it read the password:

    *cmd* 'PASS asdasd\n'
    *put* b'PASS asdasd\n'
    

    somehow it also read the \n that contains illegal character. Solve by removing the \n for each of the input value.