@@ -583,23 +583,9 @@ def get(figure_or_data, format='png', width=None, height=None):
583
583
"https://plot.ly/python/static-image-export/"
584
584
)
585
585
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'
603
589
604
590
payload = {'figure' : figure , 'format' : format }
605
591
if width is not None :
@@ -1208,23 +1194,31 @@ def api_url(cls, resource):
1208
1194
@classmethod
1209
1195
def headers (cls ):
1210
1196
credentials = get_credentials ()
1197
+
1211
1198
# todo, validate here?
1212
1199
username , api_key = credentials ['username' ], credentials ['api_key' ]
1213
1200
encoded_api_auth = base64 .b64encode (six .b ('{0}:{1}' .format (
1214
1201
username , api_key ))).decode ('utf8' )
1215
1202
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 ,
1225
1205
'plotly-client-platform' : 'python {0}' .format (version .__version__ )
1226
1206
}
1227
1207
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
+
1228
1222
def validate_credentials (credentials ):
1229
1223
"""
1230
1224
Currently only checks for truthy username and api_key
0 commit comments