UnicodeEncodeError:'latin-1'编解码器无法在位置0-9处编码字符:序数不在范围(256)中

问题描述 投票:1回答:1

我正在尝试在Python中使用plotly从时间序列中制作交互式图形,但出现此错误:UnicodeEncodeError:'latin-1'编解码器无法在位置0-9处编码字符:序数不在范围内(256 )

这是我的代码:

from pathlib import Path
import plotly
import chart_studio

chart_studio.tools.set_credentials_file(username='****',                                              
                                  api_key='*****')

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

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

def parser2(x):
    try:
        return datetime.strptime( x, '%Y-%m-%d %H:%M:%S')#
    except:
        return 0

filename = r'AT_2018_10last.csv'
datafolder = Path('C:\HiWi Rodriguez\AT 2018\Last Value')
pathfile = datafolder / filename
ts = read_csv(pathfile, header=0,  parse_dates=[0], index_col=0 ,  date_parser=parser2)#, dtype = dtypes)
ts.columns = ['A']
ts.plot()

AT = go.Scatter(x=ts.index, y=ts.A)

layout = go.Layout(title='Ambient Temperature', xaxis=dict(title='Date'),
                   yaxis=dict(title='[°C]'))

fig = go.Figure(data=AT, layout=layout)
py.iplot(fig, sharing='public')
python plotly
1个回答
0
投票

因此chart_studio似乎只允许将extended ASCII table中的字符用作用户名和密码。

根据您的错误消息,您的密码中似乎输入了错误的字符。您可以使用以下代码来检查您的密码:

YOUR_PASSWORD = "your_p♥$$w0rd!_here"

for character in YOUR_PASSWORD:
    code_point = ord(character)

    if code_point < 256:
        print(f"    ok: {character} ({code_point})")
    else:
        print(f"not ok: {character} ({code_point})")

您可以在示例输出中看到,字符的代码点为9829,因此会出现问题,因为它不在255的范围内:

确定:y(121)好的:o(111)好的:你(117)好的:r(114)好的:_(95)好:p(112)不正常:♥(9829)好的:$(36)好的:$(36)好的:w(119)好的:0(48)好的:r(114)好的:d(100)好: ! (33)好的:_(95)好的:小时(104)好的:e(101)好的:r(114)好的:e(101)

© www.soinside.com 2019 - 2024. All rights reserved.