How to Fix KeyError: ‘plotly_domain’

1. Error description

E:\PycharmProjects\cdk\venv\Scripts\python.exe E:/PycharmProjects/cdk/venv/plotly/b.py
Traceback (most recent call last):
  File "E:/PycharmProjects/cdk/venv/plotly/b.py", line 14, in <module>
    py.iplot(data,filename='Histogram');
  File "E:\PycharmProjects\cdk\venv\lib\site-packages\plotly\plotly\plotly.py", line 170, in iplot
    return tools.embed(url, **embed_options)
  File "E:\PycharmProjects\cdk\venv\lib\site-packages\plotly\tools.py", line 404, in embed
    != session.get_session_config()['plotly_domain']):
KeyError: 'plotly_domain'

Process finished with exit code 1

2. Cause of error

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

plotly.tools.set_credentials_file(username='xxx',api_key='787889Pa0GMIkz1R3Z1BHy');

C = go.Bar(
    x = [1,2,3,4,5,6,7,8],
    y = [7889,5623,9856,1254,4878,5656,3562,7445]
)

data = [C];

py.iplot(data,filename='Histogram');

3. Solutions

When drawing graphics, you need to call the plot () method instead of the iPlot () method

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

plotly.tools.set_credentials_file(username='xxx',api_key='56895656GMIkz1R3Z1BHy');

C = go.Bar(
    x = [1,2,3,4,5,6,7,8],
    y = [7889,5623,9856,1254,4878,5656,3562,7445]
)

data = [C];

py.plot(data,filename='Histogram');

Read More: