Skip to content

Commit ea84183

Browse files
committed
Merge pull request #142 from plotly/set-certificate
Set certificate
2 parents 06d8665 + a86626b commit ea84183

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

plotly/plotly/plotly.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def sign_in(username, api_key, **kwargs):
6767
_config['plotly_domain'] = kwargs.get('plotly_domain')
6868
_config['plotly_streaming_domain'] = kwargs.get('plotly_streaming_domain')
6969
_config['plotly_api_domain'] = kwargs.get('plotly_api_domain')
70+
_config['plotly_ssl_verification'] = kwargs.get('plotly_ssl_verification')
7071
# TODO: verify format of config options
7172

7273

@@ -141,7 +142,7 @@ def get_config():
141142
"""Returns either module config or file config."""
142143
config = tools.get_config_file()
143144
for config_key in config:
144-
if _config.get(config_key):
145+
if _config.get(config_key) is not None:
145146
config[config_key] = _config[config_key]
146147
return config
147148

@@ -359,7 +360,9 @@ def get_figure(file_owner_or_url, file_id=None, raw=False):
359360
raise exceptions.PlotlyError(
360361
"The 'file_id' argument must be a non-negative number."
361362
)
362-
response = requests.get(plotly_rest_url + resource, headers=headers)
363+
response = requests.get(plotly_rest_url + resource,
364+
headers=headers,
365+
verify=get_config()['plotly_ssl_verification'])
363366
if response.status_code == 200:
364367
if six.PY3:
365368
content = json.loads(response.content.decode('unicode_escape'))
@@ -579,10 +582,10 @@ def get(figure_or_data, format='png', width=None, height=None):
579582
payload['height'] = height
580583

581584
url = get_config()['plotly_domain'] + "/apigenimage/"
582-
res = requests.post(url,
583-
data=json.dumps(payload,
584-
cls=utils._plotlyJSONEncoder),
585-
headers=headers)
585+
res = requests.post(
586+
url, data=json.dumps(payload, cls=utils._plotlyJSONEncoder),
587+
headers=headers, verify=get_config()['plotly_ssl_verification']
588+
)
586589

587590
headers = res.headers
588591

@@ -682,7 +685,8 @@ def mkdirs(cls, folder_path):
682685

683686
url = _api_v2.api_url('folders')
684687

685-
res = requests.post(url, data=payload, headers=_api_v2.headers())
688+
res = requests.post(url, data=payload, headers=_api_v2.headers(),
689+
verify=get_config()['plotly_ssl_verification'])
686690

687691
_api_v2.response_handler(res)
688692

@@ -733,7 +737,8 @@ def upload(cls, grid, filename,
733737

734738
upload_url = _api_v2.api_url('grids')
735739
req = requests.post(upload_url, data=payload,
736-
headers=_api_v2.headers())
740+
headers=_api_v2.headers(),
741+
verify=get_config()['plotly_ssl_verification'])
737742

738743
res = _api_v2.response_handler(req)
739744

@@ -775,7 +780,8 @@ def append_columns(cls, columns, grid=None, grid_url=None):
775780
}
776781

777782
api_url = _api_v2.api_url('grids')+'/{grid_id}/col'.format(grid_id=grid_id)
778-
res = requests.post(api_url, data=payload, headers=_api_v2.headers())
783+
res = requests.post(api_url, data=payload, headers=_api_v2.headers(),
784+
verify=get_config()['plotly_ssl_verification'])
779785
res = _api_v2.response_handler(res)
780786

781787
cls._fill_in_response_column_ids(columns, res['cols'], grid_id)
@@ -807,7 +813,8 @@ def append_rows(cls, rows, grid=None, grid_url=None):
807813

808814
api_url = (_api_v2.api_url('grids')+
809815
'/{grid_id}/row'.format(grid_id=grid_id))
810-
res = requests.post(api_url, data=payload, headers=_api_v2.headers())
816+
res = requests.post(api_url, data=payload, headers=_api_v2.headers(),
817+
verify=get_config()['plotly_ssl_verification'])
811818
_api_v2.response_handler(res)
812819

813820
if grid:
@@ -826,7 +833,8 @@ def append_rows(cls, rows, grid=None, grid_url=None):
826833
def delete(cls, grid=None, grid_url=None):
827834
grid_id = _api_v2.parse_grid_id_args(grid, grid_url)
828835
api_url = _api_v2.api_url('grids')+'/'+grid_id
829-
res = requests.delete(api_url, headers=_api_v2.headers())
836+
res = requests.delete(api_url, headers=_api_v2.headers(),
837+
verify=get_config()['plotly_ssl_verification'])
830838
_api_v2.response_handler(res)
831839

832840

@@ -844,7 +852,8 @@ def upload(cls, meta, grid=None, grid_url=None):
844852

845853
api_url = _api_v2.api_url('grids')+'/{grid_id}'.format(grid_id=grid_id)
846854

847-
res = requests.patch(api_url, data=payload, headers=_api_v2.headers())
855+
res = requests.patch(api_url, data=payload, headers=_api_v2.headers(),
856+
verify=get_config()['plotly_ssl_verification'])
848857

849858
return _api_v2.response_handler(res)
850859

@@ -963,7 +972,8 @@ def _send_to_plotly(figure, **plot_options):
963972

964973
url = get_config()['plotly_domain'] + "/clientresp"
965974

966-
r = requests.post(url, data=payload)
975+
r = requests.post(url, data=payload,
976+
verify=get_config()['plotly_ssl_verification'])
967977
r.raise_for_status()
968978
r = json.loads(r.text)
969979
if 'error' in r and r['error'] != '':

plotly/tests/test_core/test_plotly/test_credentials.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ def test_sign_in_with_config(self):
5151
api_key = 'place holder'
5252
plotly_domain = 'test domain'
5353
plotly_streaming_domain = 'test streaming domain'
54+
plotly_ssl_verification = False
5455
py.sign_in(
5556
username,
5657
api_key,
5758
plotly_domain=plotly_domain,
58-
plotly_streaming_domain=plotly_streaming_domain
59+
plotly_streaming_domain=plotly_streaming_domain,
60+
plotly_ssl_verification=plotly_ssl_verification
5961
)
6062
config = py.get_config()
6163
self.assertEqual(config['plotly_domain'], plotly_domain)
6264
self.assertEqual(
6365
config['plotly_streaming_domain'], plotly_streaming_domain
6466
)
67+
self.assertEqual(
68+
config['plotly_ssl_verification'], plotly_ssl_verification
69+
)

plotly/tools.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def warning_on_one_line(message, category, filename, lineno, file=None, line=Non
5050
'stream_ids': []},
5151
CONFIG_FILE: {'plotly_domain': 'https://plot.ly',
5252
'plotly_streaming_domain': 'stream.plot.ly',
53-
'plotly_api_domain': 'https://api.plot.ly'}}
53+
'plotly_api_domain': 'https://api.plot.ly',
54+
'plotly_ssl_verification': True}}
5455

5556
try:
5657
os.mkdir(TEST_DIR)
@@ -142,7 +143,8 @@ def reset_credentials_file():
142143

143144
def set_config_file(plotly_domain=None,
144145
plotly_streaming_domain=None,
145-
plotly_api_domain=None):
146+
plotly_api_domain=None,
147+
plotly_ssl_verification=None):
146148
"""Set the keyword-value pairs in `~/.plotly/.config`.
147149
148150
"""
@@ -157,6 +159,8 @@ def set_config_file(plotly_domain=None,
157159
settings['plotly_streaming_domain'] = plotly_streaming_domain
158160
if isinstance(plotly_api_domain, six.string_types):
159161
settings['plotly_api_domain'] = plotly_api_domain
162+
if isinstance(plotly_ssl_verification, (six.string_types, bool)):
163+
settings['plotly_ssl_verification'] = plotly_ssl_verification
160164
utils.save_json_dict(CONFIG_FILE, settings)
161165
ensure_local_plotly_files() # make sure what we just put there is OK
162166

plotly/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.4.2'
1+
__version__ = '1.4.3'

0 commit comments

Comments
 (0)