Repository: plotly/plotly.py
Pull request: temporary share key fix
@chriddyp adding a sleep to temporarily resolve the sharekey issue. Fixes https://github.com/plotly/plotly.py/issues/719



Problem statement:
'secret' plots sometimes show up as 'private' on cloud
```
for _ in range(50):
    fig = dict(data=[{}], layout={})
    plot_url = py.plot(fig, filename='test_folder/title', fileopt='new', auto_open=False, sharing='secret')
```

^^^Running this code above makes a folder and puts secret graphs into that folder. Out of 50 plots I made, 4 of them were set to private in the cloud.

Hints from issue discussion:
fixed in https://github.com/plotly/plotly.py/pull/726
Even in the updated version of plot.ly this error is still occurring for a professional plan user. 
https://github.com/plotly/plotly.py/blob/3efe8338df9250cfb5bd7461ed5c9efeac31bb16/plotly/plotly/plotly.py#L1318 is failing silently

Commit message: temporary share key fix

Patch to review:
diff --git a/plotly/plotly/plotly.py b/plotly/plotly/plotly.py
index 93597fb0870..8791d79145b 100644
--- a/plotly/plotly/plotly.py
+++ b/plotly/plotly/plotly.py
@@ -19,6 +19,7 @@
 import copy
 import json
 import os
+import time
 import warnings
 import webbrowser
 
@@ -1304,7 +1305,6 @@ def add_share_key_to_url(plot_url, attempt=0):
     username = urlsplit.path.split('/')[1].split('~')[1]
     idlocal = urlsplit.path.split('/')[2]
     fid = '{}:{}'.format(username, idlocal)
-
     body = {'share_key_enabled': True, 'world_readable': False}
     response = v2.files.update(fid, body)
 
@@ -1312,9 +1312,12 @@ def add_share_key_to_url(plot_url, attempt=0):
     # 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']:
+    time.sleep(4)
+    share_key_enabled = v2.files.retrieve(fid).json()['share_key_enabled']
+    if not share_key_enabled:
         attempt += 1
         if attempt == 50:
+            print('Raising exception')
             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."
diff --git a/plotly/version.py b/plotly/version.py
index 79d5280f2fb..8890852d64f 100644
--- a/plotly/version.py
+++ b/plotly/version.py
@@ -1 +1 @@
-__version__ = '2.0.13'
+__version__ = '2.0.14'


Code review comments:
diff_hunk: @@ -1304,17 +1305,19 @@ def add_share_key_to_url(plot_url, attempt=0):
     username = urlsplit.path.split('/')[1].split('~')[1]
     idlocal = urlsplit.path.split('/')[2]
     fid = '{}:{}'.format(username, idlocal)
-
     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']:
+    time.sleep(4)
+    share_key_enabled = v2.files.retrieve(fid).json()['share_key_enabled']
+    if not share_key_enabled:
         attempt += 1
         if attempt == 50:
+            print('Raising exception')
path: plotly/plotly/plotly.py
text: @user1:
⚡️  this print statement