Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f939074

Browse files
committed
Changed instance of PlotlyAccountError to PlotlyLocalCredentialsError.
PlotlyAccountError is reserved for server errors where an actual check has been done. In addition, the error message for the PlotlyLocalCredentialsError is stored in exceptions.py for better use-ability.
1 parent f395108 commit f939074

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

plotly/exceptions.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class PlotlyError(Exception):
2323
pass
2424

2525

26-
2726
## Graph Objects Errors ##
2827

2928
class PlotlyGraphObjectError(PlotlyError):
@@ -139,6 +138,38 @@ def __init__(self, obj='', index='', **kwargs):
139138
**kwargs)
140139

141140

141+
## Local Config Errors ##
142+
143+
class PlotlyLocalError(PlotlyError):
144+
pass
145+
146+
147+
class PlotlyLocalCredentialsError(PlotlyLocalError):
148+
def __init__(self):
149+
message = ("\n"
150+
"Couldn't find a 'username', 'api-key' pair for you on your local "
151+
"machine. To sign in temporarily (until you stop running Python), "
152+
"run:\n"
153+
">>> import plotly.plotly as py\n"
154+
">>> py.sign_in('username', 'api_key')\n\n"
155+
"Even better, save your credentials permatently using the 'tools' "
156+
"module:\n"
157+
">>> import plotly.tools as tls\n"
158+
">>> tls.set_credentials_file(username='username', api_key='api-key')\n\n"
159+
"Note that 'username' should be a string containing YOUR Plotly "
160+
"username and 'api-key' should be a string containing YOUR Plotly "
161+
"api-key. To view your api-key:\n"
162+
"1. Visit our website: https://plot.ly/\n"
163+
"2. Sign-in using your Plotly username and password (different "
164+
"from api-key)\n"
165+
"3. Click the drop-down menu in the upper-right corner that says "
166+
"your username.\n"
167+
"4. Select 'settings' from this list.\n"
168+
"5. Under the 'profile' tab in the settings list, you will find "
169+
"your 'API Key'.\n")
170+
super(PlotlyLocalCredentialsError, self).__init__(message)
171+
172+
142173
## Server Errors ##
143174

144175
class PlotlyServerError(PlotlyError):

plotly/plotly/plotly.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,7 @@ def _send_to_plotly(figure, **plot_options):
520520
(username, api_key) = (file_credentials['username'],
521521
file_credentials['api_key'])
522522
else:
523-
raise exceptions.PlotlyAccountError("Couldn't find a username, "
524-
"api_key pair.")
523+
raise exceptions.PlotlyLocalCredentialsError()
525524

526525
kwargs = json.dumps(dict(filename=plot_options['filename'],
527526
fileopt=plot_options['fileopt'],
@@ -563,15 +562,14 @@ def _validation_key_logic():
563562
elif 'username' in creds_on_file:
564563
username = creds_on_file['username']
565564
else:
566-
raise exceptions.PlotlyAccountError("Not signed in or no username "
567-
"saved in config file") # TODO: a message that doesn't suck
568-
565+
username = None
569566
if 'api_key' in _credentials:
570567
api_key = _credentials['api_key']
571568
elif 'api_key' in creds_on_file:
572569
api_key = creds_on_file['api_key']
573570
else:
574-
raise exceptions.PlotlyAccountError("Not signed in or no api_key saved "
575-
"in config file") # TODO: a message that doesn't suck
571+
api_key = None
572+
if username is None or api_key is None:
573+
raise exceptions.PlotlyLocalCredentialsError()
576574
return (username, api_key)
577575

0 commit comments

Comments
 (0)