Skip to content

Commit 3e72710

Browse files
committed
update chunked requests sub mods.
1 parent 32e4edd commit 3e72710

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

plotly/plotly/chunked_requests/chunked_request.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import time
22
import six
33
import os
4+
import ssl
5+
46
from six.moves import http_client
57
from six.moves.urllib.parse import urlparse
6-
from ssl import SSLError
78

89

910
class Stream:
10-
def __init__(self, server, port=80, headers={}, url='/', ssl_enabled=False):
11+
def __init__(self, server, port=80, headers={}, url='/', ssl_enabled=False,
12+
ssl_verification_enabled=True):
1113
''' Initialize a stream object and an HTTP or HTTPS connection
1214
with chunked Transfer-Encoding to server:port with optional headers.
1315
'''
@@ -20,6 +22,7 @@ def __init__(self, server, port=80, headers={}, url='/', ssl_enabled=False):
2022
self._headers = headers
2123
self._url = url
2224
self._ssl_enabled = ssl_enabled
25+
self._ssl_verification_enabled = ssl_verification_enabled
2326
self._connect()
2427

2528
def write(self, data, reconnect_on=('', 200, )):
@@ -99,6 +102,19 @@ def _get_proxy_config(self):
99102

100103
return proxy_server, proxy_port
101104

105+
def _get_ssl_context(self):
106+
"""
107+
Return an unverified context if ssl verification is disabled.
108+
109+
"""
110+
111+
context = None
112+
113+
if not self._ssl_verification_enabled:
114+
context = ssl._create_unverified_context()
115+
116+
return context
117+
102118
def _connect(self):
103119
''' Initialize an HTTP/HTTPS connection with chunked Transfer-Encoding
104120
to server:port with optional headers.
@@ -111,8 +127,9 @@ def _connect(self):
111127

112128
if (proxy_server and proxy_port):
113129
if ssl_enabled:
130+
context = self._get_ssl_context()
114131
self._conn = http_client.HTTPSConnection(
115-
proxy_server, proxy_port
132+
proxy_server, proxy_port, context=context
116133
)
117134
else:
118135
self._conn = http_client.HTTPConnection(
@@ -121,7 +138,10 @@ def _connect(self):
121138
self._conn.set_tunnel(server, port)
122139
else:
123140
if ssl_enabled:
124-
self._conn = http_client.HTTPSConnection(server, port)
141+
context = self._get_ssl_context()
142+
self._conn = http_client.HTTPSConnection(
143+
server, port, context=context
144+
)
125145
else:
126146
self._conn = http_client.HTTPConnection(server, port)
127147

@@ -254,7 +274,7 @@ def _isconnected(self):
254274
# let's just assume that we're still connected and
255275
# hopefully recieve some data on the next try.
256276
return True
257-
elif isinstance(e, SSLError):
277+
elif isinstance(e, ssl.SSLError):
258278
if e.errno == 2:
259279
# errno 2 occurs when trying to read or write data, but more
260280
# data needs to be received on the underlying TCP transport

0 commit comments

Comments
 (0)