Skip to content

check that share key is enabled #726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
20 changes: 17 additions & 3 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -1308,7 +1308,21 @@ 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']
# 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 == 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']
return url_share_key


def _send_to_plotly(figure, **plot_options):
Expand Down