From 5271fccd5fe339747e4ac16b882d9eed45a78958 Mon Sep 17 00:00:00 2001 From: Chelsea Date: Thu, 6 Apr 2017 18:09:59 -0400 Subject: [PATCH 1/2] check that share key is enabled --- plotly/plotly/plotly.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plotly/plotly/plotly.py b/plotly/plotly/plotly.py index dd7067600b5..4bf7ffea0d0 100644 --- a/plotly/plotly/plotly.py +++ b/plotly/plotly/plotly.py @@ -1295,9 +1295,9 @@ def parse_grid_id_args(grid, grid_url): return grid.id -def add_share_key_to_url(plot_url): +def add_share_key_to_url(plot_url, attempt=0): """ - Update plot's url to include the secret key + Check that share key is enabled and update url to include the secret key """ urlsplit = six.moves.urllib.parse.urlparse(plot_url) @@ -1308,7 +1308,14 @@ def add_share_key_to_url(plot_url): body = {'share_key_enabled': True, 'world_readable': False} response = v2.files.update(fid, body) - return plot_url + '?share_key=' + response.json()['share_key'] + if not v2.files.retrieve(fid).json()['share_key_enabled']: + attempt += 1 + if attempt == 10: + raise Exception + add_share_key_to_url(plot_url, attempt) + + url_share_key = plot_url + '?share_key=' + response.json()['share_key'] + return url_share_key def _send_to_plotly(figure, **plot_options): From 6f3280e05d195fafb7d9cd11af2f412daf2b0257 Mon Sep 17 00:00:00 2001 From: Chelsea Date: Fri, 7 Apr 2017 11:42:00 -0400 Subject: [PATCH 2/2] bump attemps to 50, add better commenting and changelog --- CHANGELOG.md | 7 ++++--- plotly/plotly/plotly.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ead0287432a..0422e1143e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [2.0.7] - [Unreleased] +## [2.0.7] - 2017-04-07 ### Updated - Updated `plotly.min.js` to version 1.25.0 for `plotly.offline`. - See [the plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md) for additional information regarding the updates. +### Added +- Added check to verify the share key is enabled when secret charts are created. + ## [2.0.6] - 2017-03-20 ### Added - 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 See [https://github.com/nteract/nteract/pull/662](https://github.com/nteract/nteract/pull/662) for the associated PR in nteract. - 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` - -### Added - `memoize` decorator added to `plotly.utils` ### Changed diff --git a/plotly/plotly/plotly.py b/plotly/plotly/plotly.py index 4bf7ffea0d0..93597fb0870 100644 --- a/plotly/plotly/plotly.py +++ b/plotly/plotly/plotly.py @@ -1308,10 +1308,17 @@ def add_share_key_to_url(plot_url, attempt=0): body = {'share_key_enabled': True, 'world_readable': False} response = v2.files.update(fid, body) + # Sometimes a share key is added, but access is still denied. + # Check that share_key_enabled is set to true and + # retry if this is not the case + # https://github.com/plotly/streambed/issues/4089 if not v2.files.retrieve(fid).json()['share_key_enabled']: attempt += 1 - if attempt == 10: - raise Exception + if attempt == 50: + raise exceptions.PlotlyError( + "The sharekey could not be enabled at this time so the graph " + "is saved as private. Try again to save as 'secret' later." + ) add_share_key_to_url(plot_url, attempt) url_share_key = plot_url + '?share_key=' + response.json()['share_key']