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
Changes from 1 commit
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
13 changes: 10 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,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']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment here about why we're trying multiple times

attempt += 1
if attempt == 10:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be OK with bumping this up to 50 even

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 bumped to 50

raise Exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to wrap everything in plotly exceptions so that users can catch them. So just: raise exceptions.PlotlyException (or something)

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