Skip to content

Instantly share code, notes, and snippets.

@schlamar
Last active December 14, 2015 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schlamar/5080598 to your computer and use it in GitHub Desktop.
Save schlamar/5080598 to your computer and use it in GitHub Desktop.
Test urllib3 and requests for HTTPS proxy CONNECT support (https://github.com/shazow/urllib3/pull/170).
curl -L -o requests.tar.gz https://github.com/schlamar/requests/archive/new-urllib3-api.tar.gz
tar -xzvf requests.tar.gz
curl -L -o test_proxy.py https://gist.github.com/schlamar/5080598/raw/test_proxy.py
python test_proxy.py
import sys
sys.path.insert(0, 'requests-new-urllib3-api/requests/packages/')
sys.path.insert(0, 'requests-new-urllib3-api')
CA_CERTS = 'requests-new-urllib3-api/requests/cacert.pem'
import os
import urllib3
import requests
assert 'http_proxy' in os.environ, ('Configure proxy in "https_proxy" '
'environment variable')
def test_urllib3():
http = urllib3.proxy_from_url(os.environ['https_proxy'],
cert_reqs='REQUIRED',
ca_certs=CA_CERTS)
try:
http.request('GET', 'https://stackoverflow.com')
assert False, 'Expected cert verification error.'
except urllib3.exceptions.SSLError as e:
if not 'doesn\'t match either' in str(e):
assert False, 'Got wrong SSL error: %s' % e
http.request('GET', 'https://google.com')
def test_requests():
try:
requests.get('https://stackoverflow.com')
assert False, 'Expected cert verification error.'
except requests.exceptions.SSLError as e:
if not 'doesn\'t match either' in str(e):
assert False, 'Got wrong SSL error: %s' % e
requests.get('https://google.com')
requests.get('http://google.com')
if __name__ == '__main__':
test_urllib3()
test_requests()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment