SSL support!
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 9a1a413 · Browse files · 1 file·+36 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+36 added−3 removed
- other:+36 added−3 removed
Provenance
- Commit
5184f0c- Tree
cda7b71- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
9a1a413
1 file changed+36 added−3 removed
modified:requests/models.py+36 added-3 removed
5 unmodified lines6 7 This module contains the primary objects that power Requests.8 """9 10+import os11 import urllib12 import zlib13 14 from urlparse import urlparse, urlunparse, urljoin, urlsplit11 unmodified lines26 from .packages.urllib3 import connectionpool, poolmanager27 from .packages.urllib3.filepost import encode_multipart_formdata28 from .exceptions import (29 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,29- URLRequired)30+ URLRequired, SSLError)31 from .utils import (32 get_encoding_from_headers, stream_decode_response_unicode,33 decode_gzip, stream_decode_gzip, guess_filename, requote_path)34 21 unmodified lines56 allow_redirects=False,57 proxies=None,58 hooks=None,59 config=None,59- _poolmanager=None):60+ _poolmanager=None,61+ verify=None):62 63 #: Float describes the timeout of the request.64 # (Use socket.setdefaulttimeout() as fallback)65 self.timeout = timeout53 unmodified lines119 120 #: Session.121 self.session = None122 123+ #: SSL Verification.124+ self.verify = verify125+126 if headers:127 headers = CaseInsensitiveDict(self.headers)128 else:129 headers = CaseInsensitiveDict()116 unmodified lines246 config=self.config,247 timeout=self.timeout,248 _poolmanager=self._poolmanager,249 proxies = self.proxies,250+ verify = self.verify251 )252 253 request.send()254 cookies.update(request.response.cookies)175 unmodified lines430 conn = self._poolmanager.connection_from_url(url)431 else:432 conn = connectionpool.connection_from_url(url)433 434+ if url.startswith('https') and self.verify:435+436+ cert_loc = None437+438+ # Allow self-specified cert location.439+ if self.verify is not True:440+ cert_loc = self.verify441+442+443+ # Look for configuration.444+ if not cert_loc:445+ cert_loc = os.environ.get('REQUESTS_CA_BUNDLE')446+447+ # Curl compatiblity.448+ if not cert_loc:449+ cert_loc = os.environ.get('CURL_CA_BUNDLE')450+451+ # Use the awesome certifi list.452+ if not cert_loc:453+ cert_loc = __import__('certifi').where()454+455+ conn.cert_reqs = 'CERT_REQUIRED'456+ conn.ca_certs = cert_loc457+458 if not self.sent or anyway:459 460 if self.cookies:461 34 unmodified lines496 except MaxRetryError, e:497 raise ConnectionError(e)498 499 except (_SSLError, _HTTPError), e:500+ if self.verify and isinstance(e, _SSLError):501+ raise SSLError(e)502+503 raise Timeout('Request timed out.')504 505 except RequestException, e:506 if self.config.get('safe_mode', False):474- # In safe mode, catch the exception and attach it to 507+ # In safe mode, catch the exception and attach it to508 # a blank urllib3.HTTPResponse object.509 r = HTTPResponse()510 r.error = e511 else:230 unmodified lines