我正在使用带有Anaconda的ipython笔记本,而我正尝试使用plotly来绘制来自pandas数据帧的数据。在绘图之前,我确保如下所示设置我的凭据:
plotly_username = "username"
plotly_api_key = "password"
然而,我收到此错误:
[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败 (_ssl.c:581)
我按照教程设置了一个图表帐户,转到https://plot.ly/settings/api并复制并粘贴了我的用户名和密钥。难道我做错了什么?我真的不确定为什么我会收到此错误?
编辑:代码
import plotly
import plotly.plotly as p
def df_to_iplot(df):
'''
Coverting a Pandas Data Frame to Plotly interface
'''
if df.index.__class__.__name__=="DatetimeIndex":
#Convert the index to MySQL Datetime like strings
x=df.index.format()
#Alternatively, directly use x, since DateTime index is np.datetime64
#see http://nbviewer.ipython.org/gist/cparmer/7721116
#x=df.index.values.astype('datetime64[s]')
else:
x = df.index.values
lines={}
for key in df:
lines[key]={}
lines[key]["x"]=x
lines[key]["y"]=df[key].values
lines[key]["name"]=key
#Appending all lines
lines_plotly=[lines[key] for key in df]
return lines_plotly
然后我打电话给:
plotly.tools.set_credentials_file(username=plotly_username, api_key=plotly_api_key)
p.iplot(df_to_iplot(df))
ERROR:
SSLError Traceback (most recent call last)
<ipython-input-21-5ac4417b1800> in <module>()
----> 4 p.plot(df_to_iplot(vehicle_df))
C:\Users\user\AppData\Local\Continuum\Anaconda\lib\site-packages\plotly\plotly\plotly.pyc in plot(figure_or_data, validate, **plot_options)
189 pass
190 plot_options = _plot_option_logic(plot_options)
--> 191 res = _send_to_plotly(figure, **plot_options)
192 if res['error'] == '':
193 if plot_options['auto_open']:
C:\Users\user\AppData\Local\Continuum\Anaconda\lib\site-packages\plotly\plotly\plotly.pyc in _send_to_plotly(figure, **plot_options)
1253
1254 r = requests.post(url, data=payload,
-> 1255 verify=get_config()['plotly_ssl_verification'])
1256 r.raise_for_status()
1257 r = json.loads(r.text)
C:\Users\user\AppData\Local\Continuum\Anaconda\lib\site-packages\requests\api.pyc in post(url, data, json, **kwargs)
107 """
108
--> 109 return request('post', url, data=data, json=json, **kwargs)
110
111
C:\Users\user\AppData\Local\Continuum\Anaconda\lib\site-packages\requests\api.pyc in request(method, url, **kwargs)
48
49 session = sessions.Session()
---> 50 response = session.request(method=method, url=url, **kwargs)
51 # By explicitly closing the session, we avoid leaving sockets open which
52 # can trigger a ResourceWarning in some cases, and look like a memory leak
C:\Users\user\AppData\Local\Continuum\Anaconda\lib\site-packages\requests\sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
463 }
464 send_kwargs.update(settings)
--> 465 resp = self.send(prep, **send_kwargs)
466
467 return resp
C:\Users\user\AppData\Local\Continuum\Anaconda\lib\site-packages\requests\sessions.pyc in send(self, request, **kwargs)
571
572 # Send the request
--> 573 r = adapter.send(request, **kwargs)
574
575 # Total elapsed time of the request (approximately)
C:\Users\user\AppData\Local\Continuum\Anaconda\lib\site-packages\requests\adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
429 except (_SSLError, _HTTPError) as e:
430 if isinstance(e, _SSLError):
--> 431 raise SSLError(e, request=request)
432 elif isinstance(e, ReadTimeoutError):
433 raise ReadTimeout(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)