Plotly sign in failure using Python

I am new to Plotly and I am attempting to create a basic graph from the documentation provided on the Plotly site, but when I run my script within Spyder (3.3.1) I get the error message “PlotlyError: Sign in failed.”. I am using my username and api key from the .credentials file, so I am unsure of where to go next. Any help would be greatly appreciated.

import plotly 
import plotly.plotly as py
import plotly.graph_objs as go

#get plotly credentials and store in list
plty_creds = list(py.get_credentials().values())
plotly.tools.set_credentials_file(username = plty_creds[0], api_key = plty_creds[1])

trace0 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)
trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[16, 5, 11, 9]
)
data = [trace0, trace1]

py.sign_in(username = plty_creds[0], api_key = plty_creds[1])

py.plot(data, filename = 'basic-line', auto_open = True)

@curtburk

If you’ve set the credentials file already then you shouldn’t need to use py.sign_in so omitting that line shouldn’t cause you any problems. That function is for if you are working in an environment where you don’t want to write your credentials to a file (e.g a jupyter notebook hosted on server).

Also, once you have set your credentials file once, you don’t need to do it again. So

plotly.tools.set_credentials_file(username = plty_creds[0], api_key = plty_creds[1])

is also not necessary.

Finally, py.get_credentials() returns a dictionary so it would be easier and more reliable to use something like

creds = py.get_credentials()
username = creds['username']
api_key = creds['api_key']

since d.values() won’t always return values in the order you expect (in my case plty_creds[1] was an empty list not my api_key).

Thank you for the suggestions Michael, if I comment out the py_sign.in() line I get a different error that states “PlotlyRequestError: No message”. There is some additional output, but the stated error message is the final line of the output. Do you have any insight into what might be happening?

@curtburk, it’s possible that your config file got messed up. Running

plotly.tools.set_config_file(**plotly.tools.get_config_defaults())

will reset it to the default values.

hello @michaelbabyn, I have implemented your suggestion, but still coming into the same problem. This is a complete shot in the dark, but could all of this be related to corporate firewall settings? I am working on my work computer so I don’t know if this could be a problem.

As an aside I can you offline mode to plot the data