Skip to content

Commit 6b12bf2

Browse files
committed
made a warning instead
1 parent 556ef45 commit 6b12bf2

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

plotly/api/v2/utils.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,6 @@
88
from plotly.api.utils import basic_auth
99

1010

11-
HTTP_ERROR_MESSAGE = (
12-
"""Your plotly_domain and plotly_api_domain must be HTTPS and not HTTP.\n
13-
If you are not using On-Prem then run the following code to ensure your
14-
plotly_domain and plotly_api_domain start with 'https':
15-
16-
```
17-
import plotly
18-
plotly.tools.set_config_file(
19-
plotly_domain='https://plot.ly',
20-
plotly_api_domain='https://api.plot.ly'
21-
)
22-
```
23-
24-
If you are using On-Prem then you will need to use your company's
25-
domain and api_domain urls:
26-
27-
```
28-
import plotly
29-
plotly.tools.set_config_file(
30-
plotly_domain='https://plotly.your-company.com',
31-
plotly_api_domain='https://plotly.your-company.com'
32-
)
33-
```
34-
35-
Make sure to replace "your-company.com" with the URL of your Plotly On-Premise server.
36-
37-
See https://plot.ly/python/getting-started/#special-instructions-for-plotly-onpremise-users
38-
for more tips for getting started with Plotly."""
39-
)
40-
41-
4211
def make_params(**kwargs):
4312
"""
4413
Helper to create a params dict, skipping undefined entries.
@@ -107,11 +76,6 @@ def validate_response(response):
10776
if not message:
10877
message = content if content else 'No Content'
10978

110-
if len(response.history) > 0:
111-
if not response.history[0].url.startswith('https:'):
112-
raise exceptions.PlotlyRequestError(HTTP_ERROR_MESSAGE,
113-
status_code, content)
114-
11579
raise exceptions.PlotlyRequestError(message, status_code, content)
11680

11781

plotly/tools.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@
4949
ALTERNATIVE_HISTNORM = 'probability'
5050

5151

52+
http_msg = (
53+
"The plotly_domain and plotly_api_domain of your config file must start "
54+
"with 'https', 'http'.\n If you are not using On-Prem then run the "
55+
"following code to ensure your plotly_domain and plotly_api_domain start "
56+
"with 'https':\n\n\n"
57+
"import plotly\n"
58+
"plotly.tools.set_config_file(\n"
59+
" plotly_domain='https://plot.ly',\n"
60+
" plotly_api_domain='https://api.plot.ly'\n"
61+
")\n\n\n"
62+
"If you are using On-Prem then you will need to use your company's "
63+
"domain and api_domain urls:\n\n\n"
64+
"import plotly\n"
65+
"plotly.tools.set_config_file(\n"
66+
" plotly_domain='https://plotly.your-company.com',\n"
67+
" plotly_api_domain='https://plotly.your-company.com'\n"
68+
")\n\n\n"
69+
"Make sure to replace `your-company.com` with the URL of your Plotly "
70+
"On-Premise server.\nSee "
71+
"https://plot.ly/python/getting-started/#special-instructions-for-plotly-onpremise-users "
72+
"for more help with getting started with On-Prem."
73+
)
74+
75+
76+
def validate_config_file(*domains):
77+
for d in domains:
78+
if not d.lower().startswith('https'):
79+
warnings.warn(http_msg)
80+
81+
5282
# Warning format
5383
def warning_on_one_line(message, category, filename, lineno,
5484
file=None, line=None):
@@ -194,6 +224,7 @@ def set_config_file(plotly_domain=None,
194224
'sharing': sharing, 'world_readable': world_readable})
195225
settings = get_config_file()
196226
if isinstance(plotly_domain, six.string_types):
227+
validate_config_file(plotly_domain)
197228
settings['plotly_domain'] = plotly_domain
198229
elif plotly_domain is not None:
199230
raise TypeError('plotly_domain should be a string')
@@ -202,6 +233,7 @@ def set_config_file(plotly_domain=None,
202233
elif plotly_streaming_domain is not None:
203234
raise TypeError('plotly_streaming_domain should be a string')
204235
if isinstance(plotly_api_domain, six.string_types):
236+
validate_config_file(plotly_api_domain)
205237
settings['plotly_api_domain'] = plotly_api_domain
206238
elif plotly_api_domain is not None:
207239
raise TypeError('plotly_api_domain should be a string')
@@ -244,9 +276,10 @@ def get_config_file(*args):
244276
"""
245277
if check_file_permissions():
246278
ensure_local_plotly_files() # make sure what's there is OK
247-
return utils.load_json_dict(CONFIG_FILE, *args)
279+
returned_obj = utils.load_json_dict(CONFIG_FILE, *args)
248280
else:
249-
return FILE_CONTENT[CONFIG_FILE]
281+
returned_obj = FILE_CONTENT[CONFIG_FILE]
282+
return returned_obj
250283

251284

252285
def reset_config_file():

0 commit comments

Comments
 (0)