Skip to content

Commit d906dc7

Browse files
committed
check that secret graphs are accessible before returning them. if they aren't accessible, attempt to add the share key again
1 parent 390c09d commit d906dc7

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

plotly/plotly/plotly.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ def validate_credentials(credentials):
13201320
raise exceptions.PlotlyLocalCredentialsError()
13211321

13221322

1323-
def add_share_key_to_url(plot_url):
1323+
def add_share_key_to_url(plot_url, attempt=0):
13241324
"""
13251325
Update plot's url to include the secret key
13261326
@@ -1343,8 +1343,19 @@ def add_share_key_to_url(plot_url):
13431343
str_content = new_response.content.decode('utf-8')
13441344

13451345
new_response_data = json.loads(str_content)
1346+
13461347
plot_url += '?share_key=' + new_response_data['share_key']
13471348

1349+
# sometimes a share key is added, but access is still denied
1350+
# check for access, and retry a couple of times if this is the case
1351+
embed_url = plot_url.split('?')[0] + '.embed' + plot_url.split('?')[1]
1352+
access_res = requests.get(embed_url)
1353+
if access_res.status_code == 404:
1354+
attempt += 1
1355+
if attempt == 5:
1356+
break
1357+
plot_url = add_share_key_to_url(plot_url.split('?')[0], attempt)
1358+
13481359
return plot_url
13491360

13501361

0 commit comments

Comments
 (0)