Python openssl问题

时间:2010-09-18 18:08:37

标签: python openssl

我正在尝试在python中编写一个简单的邮件检索程序。似乎联系正在建立。但是当我尝试用用户名授权时,我没有得到服务器的回复。谁能告诉我这里出了什么问题?

import socket, sys
from OpenSSL import SSL

ctx = SSL.Context(SSL.SSLv23_METHOD)

print "Creating socket"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "done"

ssl = SSL.Connection(ctx, s)

print "Establishing Connection"
ssl.connect(("pop.gmail.com", 995))
print "done"

print "Requesting Documents"
print "done"

try:
    buf = ssl.read(4096)
except SSL.ZeroReturnError:
    print "1"
sys.stdout.write(buf)

ssl.send("USER username")

try:
    buf2 = ssl.recv(4096)
except SSL.ZeroReturnError:
    print "2"
sys.stdout.write(buf2)

ssl.send("PASS secret")

try:
    buf3 = ssl.read(4096)
except SSL.ZeroReturnError:
    print "2"
sys.stdout.write(buf3)

print "connected"
ssl.close()

1 个答案:

答案 0 :(得分:1)

使用\ r \ n

结束字符串