23
23
import six
24
24
import base64
25
25
import requests
26
- from requests .auth import HTTPBasicAuth
27
26
28
27
if sys .version [:1 ] == '2' :
29
28
from urlparse import urlparse
@@ -587,9 +586,20 @@ def get(figure_or_data, format='png', width=None, height=None):
587
586
credentials = get_credentials ()
588
587
validate_credentials (credentials )
589
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
+
590
598
headers = {'Plotly-Version' : version .__version__ ,
591
599
'Content-Type' : 'application/json' ,
592
- 'Plotly-Client-Platform' : 'python' }
600
+ 'Plotly-Client-Platform' : 'python' ,
601
+ 'Authorization' : 'Basic ' + encoded_proxy_auth ,
602
+ 'Plotly-Authorization' : 'Basic ' + encoded_api_auth }
593
603
594
604
payload = {'figure' : figure , 'format' : format }
595
605
if width is not None :
@@ -602,7 +612,6 @@ def get(figure_or_data, format='png', width=None, height=None):
602
612
res = requests .post (
603
613
url , data = json .dumps (payload , cls = utils .PlotlyJSONEncoder ),
604
614
headers = headers , verify = get_config ()['plotly_ssl_verification' ],
605
- auth = HTTPBasicAuth (username , api_key )
606
615
)
607
616
608
617
headers = res .headers
@@ -1200,17 +1209,22 @@ def api_url(cls, resource):
1200
1209
def headers (cls ):
1201
1210
credentials = get_credentials ()
1202
1211
# todo, validate here?
1203
- un , api_key = credentials ['username' ], credentials ['api_key' ]
1204
- encoded_un_key_pair = base64 .b64encode (
1205
- six .b ('{0}:{1}' .format (un , api_key ))
1206
- ).decode ('utf8' )
1212
+ username , api_key = credentials ['username' ], credentials ['api_key' ]
1213
+ encoded_api_auth = base64 .b64encode (six .b ('{0}:{1}' .format (
1214
+ username , api_key ))).decode ('utf8' )
1215
+
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' )
1207
1221
1208
1222
return {
1209
- 'authorization' : 'Basic ' + encoded_un_key_pair ,
1223
+ 'authorization' : 'Basic ' + encoded_proxy_auth ,
1224
+ 'plotly-authorization' : 'Basic ' + encoded_api_auth ,
1210
1225
'plotly-client-platform' : 'python {0}' .format (version .__version__ )
1211
1226
}
1212
1227
1213
-
1214
1228
def validate_credentials (credentials ):
1215
1229
"""
1216
1230
Currently only checks for truthy username and api_key
0 commit comments