def validate_credentials(credentials): """ Currently only checks for truthy username and api_key """ username = credentials.get('username') api_key = credentials.get('api_key') if not username or not api_key: raise exceptions.PlotlyLocalCredentialsError()
def _get_session_username_and_key(): file_credentials = tools.get_credentials_file() if ('username' in _credentials) and ('api_key' in _credentials): username, api_key = _credentials['username'], _credentials['api_key'] elif ('username' in file_credentials) and ('api_key' in file_credentials): (username, api_key) = (file_credentials['username'], file_credentials['api_key']) else: raise exceptions.PlotlyLocalCredentialsError() return username, api_key
def _validation_key_logic(): creds_on_file = tools.get_credentials_file() if 'username' in _credentials: username = _credentials['username'] elif 'username' in creds_on_file: username = creds_on_file['username'] else: username = None if 'api_key' in _credentials: api_key = _credentials['api_key'] elif 'api_key' in creds_on_file: api_key = creds_on_file['api_key'] else: api_key = None if username is None or api_key is None: raise exceptions.PlotlyLocalCredentialsError() return (username, api_key)
def _send_to_plotly(figure, **plot_options): """ """ fig = tools._replace_newline(figure) # does not mutate figure data = json.dumps(fig['data'] if 'data' in fig else [], cls=utils._plotlyJSONEncoder) file_credentials = tools.get_credentials_file() if ('username' in _credentials) and ('api_key' in _credentials): username, api_key = _credentials['username'], _credentials['api_key'] elif ('username' in file_credentials) and ('api_key' in file_credentials): (username, api_key) = (file_credentials['username'], file_credentials['api_key']) else: raise exceptions.PlotlyLocalCredentialsError() kwargs = json.dumps(dict(filename=plot_options['filename'], fileopt=plot_options['fileopt'], world_readable=plot_options['world_readable'], layout=fig['layout'] if 'layout' in fig else {}), cls=utils._plotlyJSONEncoder) payload = dict( platform= 'python', # TODO: It'd be cool to expose the platform for RaspPi and others version=version.__version__, args=data, un=username, key=api_key, origin='plot', kwargs=kwargs) url = tools.get_config_file()['plotly_domain'] + "/clientresp" r = requests.post(url, data=payload) r.raise_for_status() r = json.loads(r.text) if 'error' in r and r['error'] != '': print((r['error'])) if 'warning' in r and r['warning'] != '': warnings.warn(r['warning']) if 'message' in r and r['message'] != '': print((r['message'])) return r