简体   繁体   English

尝试解析字符串时出现Python poplib错误

[英]Python poplib error when trying to parse in a string

I am using poplib to get email from the POP3 server. 我正在使用poplib从POP3服务器获取电子邮件。

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: 这是python代码:

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. 但是,在该功能中,当我尝试输入密码(表示为“ pa”)并直接输入时,它可以工作。 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. 它也会以某种方式读取包含非法字符的\\ n。 Solve by removing the \\n for each of the input value. 通过消除每个输入值的\\ n来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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