I am trying to verify the that target exposes a https web service. I have code to connect via HTTP but I am not sure how to connect via HTTPS. I have read you use SSL but I have also read that it did not support certificate errors. The code I have got is from the python docs:
conn = httplib.HTTPConnection("www.python.org")
r1 = conn.getresponse()
print r1.status, r1.reason
from OpenSSL import SSL
response = urllib2.urlopen('https://example.com')
print 'response headers: "%s"' % response.info()
except IOError, e:
if hasattr(e, 'code'): # HTTPError
print 'http error code: ', e.code
elif hasattr(e, 'reason'): # URLError
print "can't connect, reason: ", e.reason
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/build/workspace/downloads/Python-2.6.4/Lib/urllib.py", line 87, in urlopen
File "/home/build/workspace/downloads/Python-2.6.4/Lib/urllib.py", line 203, in open
return self.open_unknown(fullurl, data)
File "/home/build/workspace/downloads/Python-2.6.4/Lib/urllib.py", line 215, in open_unknown
raise IOError, ('url error', 'unknown url type', type)
IOError: [Errno url error] unknown url type: 'https'
Note: HTTPS support is only available if the socket module was compiled with SSL support.
#!/usr/bin/env python import httplib c = httplib.HTTPSConnection("ccc.de") c.request("GET", "/") response = c.getresponse() print response.status, response.reason data = response.read() print data # => # 200 OK # <!DOCTYPE html ....
To verify if SSL is enabled, try:
>>> import socket >>> socket.ssl <function ssl at 0x4038b0>