简体   繁体   中英

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 xxx@gmail.com'
*put* b'USER xxx@gmail.com'
*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('test@gmail.com','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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM