def get_headers(): """ Using session credentials/config, get headers for a V2 API request. Users may have their own proxy layer and so we free up the `authorization` header for this purpose (instead adding the user authorization in a new `plotly-authorization` header). See pull #239. :returns: (dict) Headers to add to a requests.request call. """ creds = config.get_credentials() headers = { 'plotly-client-platform': 'python {}'.format(version.stable_semver()), 'content-type': 'application/json' } plotly_auth = basic_auth(creds['username'], creds['api_key']) proxy_auth = basic_auth(creds['proxy_username'], creds['proxy_password']) if config.get_config()['plotly_proxy_authorization']: headers['authorization'] = proxy_auth if creds['username'] and creds['api_key']: headers['plotly-authorization'] = plotly_auth else: if creds['username'] and creds['api_key']: headers['authorization'] = plotly_auth return headers
def get_headers(): """ Using session credentials/config, get headers for a V2 API request. Users may have their own proxy layer and so we free up the `authorization` header for this purpose (instead adding the user authorization in a new `plotly-authorization` header). See pull #239. :returns: (dict) Headers to add to a requests.request call. """ creds = config.get_credentials() headers = { 'plotly-client-platform': 'python {}'.format(version.stable_semver()), 'content-type': 'application/json' } plotly_auth = basic_auth(creds['username'], creds['api_key']) proxy_auth = basic_auth(creds['proxy_username'], creds['proxy_password']) if config.get_config()['plotly_proxy_authorization']: headers['authorization'] = proxy_auth if creds['username'] and creds['api_key']: headers['plotly-authorization'] = plotly_auth else: if creds['username'] and creds['api_key']: headers['authorization'] = plotly_auth return headers
def clientresp(data, **kwargs): """ Deprecated endpoint, still used because it can parse data out of a plot. When we get around to forcing users to create grids and then create plots, we can finally get rid of this. :param (list) data: The data array from a figure. """ creds = config.get_credentials() cfg = config.get_config() dumps_kwargs = {'sort_keys': True, 'cls': utils.PlotlyJSONEncoder} payload = { 'platform': 'python', 'version': version.stable_semver(), 'args': _json.dumps(data, **dumps_kwargs), 'un': creds['username'], 'key': creds['api_key'], 'origin': 'plot', 'kwargs': _json.dumps(kwargs, **dumps_kwargs) } url = '{plotly_domain}/clientresp'.format(**cfg) response = request('post', url, data=payload) # Old functionality, just keeping it around. parsed_content = response.json() if parsed_content.get('warning'): warnings.warn(parsed_content['warning']) if parsed_content.get('message'): print(parsed_content['message']) return response
def get_headers(): """ Using session credentials/config, get headers for a v1 API request. Users may have their own proxy layer and so we free up the `authorization` header for this purpose (instead adding the user authorization in a new `plotly-authorization` header). See pull #239. :returns: (dict) Headers to add to a requests.request call. """ headers = {} creds = config.get_credentials() proxy_auth = basic_auth(creds['proxy_username'], creds['proxy_password']) if config.get_config()['plotly_proxy_authorization']: headers['authorization'] = proxy_auth return headers
def get_headers(): """ Using session credentials/config, get headers for a v1 API request. Users may have their own proxy layer and so we free up the `authorization` header for this purpose (instead adding the user authorization in a new `plotly-authorization` header). See pull #239. :returns: (dict) Headers to add to a requests.request call. """ headers = {} creds = config.get_credentials() proxy_auth = basic_auth(creds['proxy_username'], creds['proxy_password']) if config.get_config()['plotly_proxy_authorization']: headers['authorization'] = proxy_auth return headers