Name: Anonymous 2008-06-19 16:45
I have the following Python code:
but when I run it I get the error:
This occurs when the server is sending data back to the client. Any ideas?
from OpenSSL import SSL
import thread, socket
TARGET_HOST = 'server.example.com'
TARGET_PORT = 443
CERT_FILE = 'server.pem'
LISTEN_PORT = 443
def forwarder(src, dst):
data = ' '
while data:
data = src.recv(4096)
print data
if data:
dst.sendall(data)
else:
src.shutdown(socket.SHUT_RD)
dst.shutdown(socket.SHUT_WR)
def sslforwarder((cli, endpoint)):
print "connection from ", endpoint
ctx = SSL.Context(SSL.SSLv23_METHOD)
srv = SSL.Connection(ctx, socket.socket())
srv.setblocking(1)
srv.connect((TARGET_HOST, TARGET_PORT))
thread.start_new_thread(forwarder, (cli, srv))
thread.start_new_thread(forwarder, (srv, cli))
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.use_privatekey_file(CERT_FILE)
ctx.use_certificate_file(CERT_FILE)
ss = SSL.Connection(ctx, socket.socket())
ss.setblocking(1)
ss.bind(('0.0.0.0', LISTEN_PORT))
ss.listen(5)
try:
while True:
sslforwarder(ss.accept())
except KeyboardInterrupt:
raise SystemExitbut when I run it I get the error:
Fatal Python error: PyEval_RestoreThread: NULL tstate
AbortedThis occurs when the server is sending data back to the client. Any ideas?