Python套接字smtp程序在请求usernam后挂起

2024-10-01 19:24:28 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我在做smtp套接字程序。我用的是gmail smtp。我面临的身份验证问题,因为我的代码挂起后,服务器要求我的用户名。下面是我的身份验证码

auth = 'AUTH LOGIN\r\n'
clientSocketSSL.send(auth.encode())
recv1 = clientSocketSSL.recv(1024).decode()
print(recv1)
if recv1[:3] != '334':
   print('334 reply not received from server')

username = base64.b64encode(b'******@gmail.com\r\n')
clientSocketSSL.send(username)
recv1 = clientSocketSSL.recv(1024).decode()
print(recv1)
if recv1[:3] != '334':
   print('334 reply not received from server')

password = base64.b64encode(b'*******\r\n')
clientSocketSSL.send(password)
recv1 = clientSocketSSL.recv(1024).decode()
print(recv1)
if recv1[:3] != '235':
   print('235 reply not received from server')

Tags: fromauthsendifservernotreplysmtp
1条回答
网友
1楼 · 发布于 2024-10-01 19:24:28

您不应该在用base64编码的字符串中包含\r\n。它需要在base64编码的用户名或密码之后发送

username = base64.b64encode(b'******@gmail.com\r\n')
clientSocketSSL.send((username + '\r\n'));

相关问题 更多 >

    热门问题