开发者

Python HTTPSConnection.close() does not appear to close the connection?

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"开发者_JAVA技巧

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.


Turns out that if you send the "Connection: close" HTTP header, this isn't an issue - although I still think that .close() should actually close the connection like it does for HTTPConnection.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜