0
votes

I want to find a correct way of verify that website is https enable by providing its url

import httplib
conn = httplib.HTTPSConnection("www.python.org")
conn.request("GET", "/")
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
conn.request("GET", "/")
r2 = conn.getresponse()
print r2.status, r2.reason
data2 = r2.read()
conn.close()

but i'm getting following error

Traceback (most recent call last): File "C:/Users/muhammad.faisal/Documents/NLP/Main.py", line 54, in conn.request("GET", "/") File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\httplib.py", line 1042, in request self._send_request(method, url, body, headers) File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\httplib.py", line 1082, in _send_request self.endheaders(body) File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\httplib.py", line 1038, in endheaders self._send_output(message_body) File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\httplib.py", line 882, in _send_output self.send(msg) File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\httplib.py", line 844, in send self.connect() File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\httplib.py", line 1255, in connect HTTPConnection.connect(self) File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\httplib.py", line 821, in connect self.timeout, self.source_address) File "C:\Users\muhammad.faisal\AppData\Local\Continuum\Anaconda2\lib\socket.py", line 557, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 11002] getaddrinfo failed

1
"..getaddrinfo failed.." - your DNS cannot does not resolve the hostname you have given to an IP address. This might be a problem of your DNS setup or that you have given the wrong name. In both cases the problem is not the Python code.Steffen Ullrich
Error occurs after calling get call conn.request("GET", "/") r1 = conn.getresponse() print r1.status, r1.reason data1 = r1.read() conn.request("GET", "/") r2 = conn.getresponse() print r2.status, r2.reason data2 = r2.read() conn.close()Faisal
With "problem is not the Python code" I mean that the reason the code is failing has nothing to do with your specific code, but is a result from either a bad DNS setup or the wrong domain given. Other applications might be affect by the same problem on the same system when accessing the same host.Steffen Ullrich

1 Answers

0
votes

In tried to execute on my system. Its working corrrectly.

In [8]: import httplib

In [9]: conn = httplib.HTTPSConnection("www.python.org")

In [10]: conn.request("GET", "/")

In [11]: r1 = conn.getresponse()

In [12]: print r1.status, r1.reason 200 OK

In [13]: data1 = r1.read()

In [14]: conn.request("GET", "/")

In [15]: r2 = conn.getresponse()

In [16]: print r2.status, r2.reason 200 OK

In [17]: data2 = r2.read()

In [18]: conn.close()

You have might be having problem in httplib package. Try installing again My python version is Python 2.7.6