开发者

Python openssl problem

开发者 https://www.devze.com 2023-01-16 12:54 出处:网络
I\'m trying to write a simple mail retrieval program in python. It seems the connection is getting established. But when I try to authorize it with the username, I don\'t get a reply from the server.

I'm trying to write a simple mail retrieval program in python. It seems the connection is getting established. But when I try to authorize it with the username, I don't get a reply from the server. Can anyone tell me what is going wrong here?

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.Zero开发者_如何学JAVAReturnError:
    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()


End the string with a \r\n

0

精彩评论

暂无评论...
验证码 换一张
取 消