Skip to content

Commit 3efe833

Browse files
authored
Merge pull request #726 from plotly/secret_fix
check that share key is enabled
2 parents 1e686cf + 6f3280e commit 3efe833

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Diff for: CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## [2.0.7] - [Unreleased]
5+
## [2.0.7] - 2017-04-07
66
### Updated
77
- Updated `plotly.min.js` to version 1.25.0 for `plotly.offline`.
88
- See [the plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md) for additional information regarding the updates.
99

10+
### Added
11+
- Added check to verify the share key is enabled when secret charts are created.
12+
1013
## [2.0.6] - 2017-03-20
1114
### Added
1215
- Added a new mimetype 'text/vnd.plotly.v1+html' for `iplot` outputs.
@@ -37,8 +40,6 @@ Note: This release's installation was broken. It has been removed from PyPI
3740
See [https://github.com/nteract/nteract/pull/662](https://github.com/nteract/nteract/pull/662)
3841
for the associated PR in nteract.
3942
- As part of the above, plotly output now prints with a [custom mimetype](https://github.com/plotly/plotly.py/blob/f65724f06b894a5db94245ee4889c632b887d8ce/plotly/offline/offline.py#L348) - `application/vnd.plotly.v1+json`
40-
41-
### Added
4243
- `memoize` decorator added to `plotly.utils`
4344

4445
### Changed

Diff for: plotly/plotly/plotly.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -1295,9 +1295,9 @@ def parse_grid_id_args(grid, grid_url):
12951295
return grid.id
12961296

12971297

1298-
def add_share_key_to_url(plot_url):
1298+
def add_share_key_to_url(plot_url, attempt=0):
12991299
"""
1300-
Update plot's url to include the secret key
1300+
Check that share key is enabled and update url to include the secret key
13011301
13021302
"""
13031303
urlsplit = six.moves.urllib.parse.urlparse(plot_url)
@@ -1308,7 +1308,21 @@ def add_share_key_to_url(plot_url):
13081308
body = {'share_key_enabled': True, 'world_readable': False}
13091309
response = v2.files.update(fid, body)
13101310

1311-
return plot_url + '?share_key=' + response.json()['share_key']
1311+
# Sometimes a share key is added, but access is still denied.
1312+
# Check that share_key_enabled is set to true and
1313+
# retry if this is not the case
1314+
# https://github.com/plotly/streambed/issues/4089
1315+
if not v2.files.retrieve(fid).json()['share_key_enabled']:
1316+
attempt += 1
1317+
if attempt == 50:
1318+
raise exceptions.PlotlyError(
1319+
"The sharekey could not be enabled at this time so the graph "
1320+
"is saved as private. Try again to save as 'secret' later."
1321+
)
1322+
add_share_key_to_url(plot_url, attempt)
1323+
1324+
url_share_key = plot_url + '?share_key=' + response.json()['share_key']
1325+
return url_share_key
13121326

13131327

13141328
def _send_to_plotly(figure, **plot_options):

0 commit comments

Comments
 (0)