|
3 | 3 |
|
4 | 4 | from .util import PY_3_OR_HIGHER
|
5 | 5 |
|
| 6 | +try: |
| 7 | + import ssl |
| 8 | +except ImportError: |
| 9 | + _HAVE_SSL = False |
| 10 | +else: |
| 11 | + _HAVE_SSL = True |
| 12 | + |
6 | 13 | if PY_3_OR_HIGHER:
|
7 | 14 | import urllib.request as urllib_request
|
8 | 15 | import urllib.error as urllib_error
|
@@ -206,9 +213,12 @@ def __iter__(self):
|
206 | 213 | yield self.timeout_token
|
207 | 214 |
|
208 | 215 |
|
209 |
| -def handle_stream_response(req, uri, arg_data, block, timeout, heartbeat_timeout): |
| 216 | +def handle_stream_response(req, uri, arg_data, block, timeout, heartbeat_timeout, verify_context=True): |
210 | 217 | try:
|
211 |
| - handle = urllib_request.urlopen(req,) |
| 218 | + context = None |
| 219 | + if not verify_context and _HAVE_SSL: |
| 220 | + context = ssl._create_unverified_context() |
| 221 | + handle = urllib_request.urlopen(req, context=context) |
212 | 222 | except urllib_error.HTTPError as e:
|
213 | 223 | raise TwitterHTTPError(e, uri, 'json', arg_data)
|
214 | 224 | return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout, heartbeat_timeout))
|
@@ -258,7 +268,7 @@ def __init__(self, domain="stream.twitter.com", secure=True, auth=None,
|
258 | 268 | uriparts = (str(api_version),)
|
259 | 269 |
|
260 | 270 | class TwitterStreamCall(TwitterCall):
|
261 |
| - def _handle_response(self, req, uri, arg_data, _timeout=None): |
| 271 | + def _handle_response(self, req, uri, arg_data, _timeout=None, verify_context=True): |
262 | 272 | return handle_stream_response(
|
263 | 273 | req, uri, arg_data, block,
|
264 | 274 | _timeout or timeout, heartbeat_timeout)
|
|
0 commit comments