Making multiple SSL requests in Python 2.x

I have a Python program that needs to do a lot of HTTPS communication with a third party server on the other side of the world.

Every time a program wants to communicate with this server, it starts a new HTTPS request.

I realized this is very inefficient because then the SSL handshake has to be done every time, which takes many rounds, which is very expensive due to how far away we are from the server.

Is there a way to make subsequent HTTPS requests fast after the first? (I don't know much about SSL, and I don't know if that means keeping the connection alive or any other thing.)

(One thing I've seen might help ssl.SSLContext

, but it's only available in Python 3.2, while we're working with Python 2.7.)

+3


source to share


1 answer


I don't know the specifics, but two thoughts come to mind:

1) You can just do each connection on a different processor in parallel using multiprocessing or even multithreading. So SSL handshakes are still slow, but it doesn't really matter as they are done in parallel.



2) You can try to make sure you are using HTTP / 1.1 and not HTTP / 1.0; presumably the latter allows connections to be reused.

0


source







All Articles