Skip to content

Commit 612baca

Browse files
committed
check for plotly_proxy_authorization flag when setting headers for proxy vs api auth
1 parent f417071 commit 612baca

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

plotly/plotly/plotly.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -583,23 +583,9 @@ def get(figure_or_data, format='png', width=None, height=None):
583583
"https://plot.ly/python/static-image-export/"
584584
)
585585

586-
credentials = get_credentials()
587-
validate_credentials(credentials)
588-
username, api_key = credentials['username'], credentials['api_key']
589-
encoded_api_auth = base64.b64encode(six.b('{0}:{1}'.format(
590-
username, api_key))).decode('utf8')
591-
592-
# custom enterprise + proxy authentication
593-
proxy_username = credentials['proxy_username']
594-
proxy_passwd = credentials['proxy_passwd']
595-
encoded_proxy_auth = base64.b64encode(six.b('{0}:{1}'.format(
596-
proxy_username, proxy_passwd))).decode('utf8')
597-
598-
headers = {'Plotly-Version': version.__version__,
599-
'Content-Type': 'application/json',
600-
'Plotly-Client-Platform': 'python',
601-
'Authorization': 'Basic ' + encoded_proxy_auth,
602-
'Plotly-Authorization': 'Basic ' + encoded_api_auth}
586+
headers = _api_v2.headers()
587+
headers['plotly_version'] = version.__version__
588+
headers['content-type'] = 'application/json'
603589

604590
payload = {'figure': figure, 'format': format}
605591
if width is not None:
@@ -1208,23 +1194,31 @@ def api_url(cls, resource):
12081194
@classmethod
12091195
def headers(cls):
12101196
credentials = get_credentials()
1197+
12111198
# todo, validate here?
12121199
username, api_key = credentials['username'], credentials['api_key']
12131200
encoded_api_auth = base64.b64encode(six.b('{0}:{1}'.format(
12141201
username, api_key))).decode('utf8')
12151202

1216-
# custom enterprise + proxy authentication
1217-
proxy_username = credentials['proxy_username']
1218-
proxy_passwd = credentials['proxy_passwd']
1219-
encoded_proxy_auth = base64.b64encode(six.b('{0}:{1}'.format(
1220-
proxy_username, proxy_passwd))).decode('utf8')
1221-
1222-
return {
1223-
'authorization': 'Basic ' + encoded_proxy_auth,
1224-
'plotly-authorization': 'Basic ' + encoded_api_auth,
1203+
headers = {
1204+
'authorization': 'Basic ' + encoded_api_auth,
12251205
'plotly-client-platform': 'python {0}'.format(version.__version__)
12261206
}
12271207

1208+
if get_config()['plotly_proxy_authorization']:
1209+
1210+
# custom enterprise + proxy authentication
1211+
proxy_username = credentials['proxy_username']
1212+
proxy_passwd = credentials['proxy_passwd']
1213+
encoded_proxy_auth = base64.b64encode(six.b('{0}:{1}'.format(
1214+
proxy_username, proxy_passwd))).decode('utf8')
1215+
1216+
headers['authorization'] = 'Basic ' + encoded_proxy_auth
1217+
headers['plotly-authorization'] = 'Basic ' + encoded_api_auth
1218+
1219+
return headers
1220+
1221+
12281222
def validate_credentials(credentials):
12291223
"""
12301224
Currently only checks for truthy username and api_key

0 commit comments

Comments
 (0)