I am having problems connecting via SNI Proxy server using Python, the following code snippet shows the connection and executing the script results in different connection errors (handshake, wrong version) depending upon which version of ssl is used:
#!/usr/bin/python
import requests
import ssl
from requests.adapters import HTTPAdapter
try:
from requests.packages.urllib3.poolmanager import PoolManager
except:
from urllib3.poolmanager import PoolManager
class SSLAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
ssl_version=ssl.PROTOCOL_TLSv1
#ssl_version=ssl.PROTOCOL_SSLv23
#ssl_version=ssl.PROTOCOL_SSLv3
assert_hostname = 'netflix.com'
self.poolmanager = PoolManager(num_pools=connections,maxsize=maxsize,block=block,ssl_version=ssl_version,assert_hostname=assert_hostname)
def newSession():
s = requests.Session()
s.mount('https://', SSLAdapter())
s.headers.update({'User-Agent': 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.6 Safari/537.36'})
return s
urlMain = "https://www.netflix.com"
session = None
session = newSession()
session.get(urlMain, verify=False).text
This results in:
requests.exceptions.SSLError: [Errno 1] _ssl.c:510: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
Looking at the logs from the sniproxy server, you can see that the servername is omitted None[];
2015-02-22 08:25:23 000.000.73.222:59288 -> 000.00.77.145:443 -> NONE [] 0/0 bytes tx 0/0 bytes rx 20.179 seconds
How can I modify the script so that it sends the servername with the request ?