Python HTTPSConnection.close() does not appear to close the connection?
- by Dave
I'm not sure if this is a bug or if I'm just doing something wrong. If I were to do an HTTP connection like this:
import httplib
http_connection = httplib.HTTPConnection("192.168.192.196")
http_connection.request("GET", "/")
http_connection.sock.settimeout(20)
response = http_connection.getresponse()
data = response.read()
http_connection.close()
Then at a DOS prompt, I do this:
netstat -ano | find /i "192.168.192.196:80" | find /i "ESTABLISHED"
I get nothing.
However, if I do the same thing, but change it to an HTTPSConnection:
import httplib
http_connection = httplib.HTTPSConnection("192.168.192.196")
http_connection.request("GET", "/")
http_connection.sock.settimeout(20)
response = http_connection.getresponse()
data = response.read()
http_connection.close()
Then do this:
netstat -ano | find /i "192.168.192.196:443" | find /i "ESTABLISHED"
I will actually see that the connection remains established until I actually ^Z out of the Python shell.
This is happening in one of the applications I'm responsible for. Python isn't actually hanging there - it's simply leaving the connection open.
Am I doing something wrong here? Do I need extra code to close the HTTPS connection?
This is Python 2.6.4, btw.