Python2.5的SMTPAuthenticationError(334, 'UGFzc3dvcmQ6')

来源:互联网 发布:淘宝代付可以看出来吗 编辑:程序博客网 时间:2024/06/05 11:22

http://liguangming.com/view/780

 

前段时间突然发现blog的post to qzone的插件不能使用了,返回的异常如下:

File "C:/Python25/lib/smtplib.py", line 591, in login
    raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (334, 'UGFzc3dvcmQ6')

通过抓包发现stmtp.qq.com

connect: ('smtp.qq.com', 25)
connect: ('58.251.150.237', 25)
reply: '220 Esmtp QQ Mail Server/r/n'
reply: retcode (220); Msg: Esmtp QQ Mail Server
connect: Esmtp QQ Mail Server
send: 'ehlo [192.168.1.177]/r/n'
reply: '250-esmtp.qq.com/r/n'
reply: '250-PIPELINING/r/n'
reply: '250-SIZE 52428800/r/n'
reply: '250-AUTH LOGIN/r/n'
reply: '250-AUTH=LOGIN/r/n'
reply: '250 8BITMIME/r/n'
reply: retcode (250); Msg: esmtp.qq.com
PIPELINING
SIZE 52428800
AUTH LOGIN
AUTH=LOGIN
8BITMIME
send: 'AUTH LOGIN **********/r/n'
reply: '334 VXNlcm5hbWU6/r/n'
reply: retcode (334); Msg: VXNlcm5hbWU6
send: '*****/r/n'
reply: '334 UGFzc3dvcmQ6/r/n'
reply: retcode (334); Msg: UGFzc3dvcmQ6

发现邮件服务器返回的是 AUTH=LOGIN,多了一个'=',打开smtplib.py找到

elif authmethod == AUTH_LOGIN:
    (code, resp) = self.docmd("AUTH",
        "%s %s" % (AUTH_LOGIN, encode_base64(user, eol="")))
    if code != 334:
        raise SMTPAuthenticationError(code, resp)
    (code, resp) = self.docmd(encode_base64(password, eol=""))

修改为:

elif authmethod == AUTH_LOGIN:
    # Three stage: 1. sent "AUTH LOGIN"; 2. sent "user name"; 3. sent "password".
    (code, resp) = self.docmd("AUTH", AUTH_LOGIN)
    if code != 334:
        raise SMTPAuthenticationError(code, resp)
    (code, resp) = self.docmd(encode_base64(user, eol=""))
    if code != 334:
        raise SMTPAuthenticationError(code, resp)
    (code, resp) = self.docmd(encode_base64(password, eol=""))

找到

if method in authlist:
    authmethod = method
    break

修改为:

if method in authlist or ('=%s' % method) in authlist:
    authmethod = method
    break

最好是将此文件另存到你的项目文件里调用,这样就不需要换个环境就先要修改smtplib.py.

原创粉丝点击