加载 .sav 文件时出现 UnicodeDecodeError

时间:2021-02-09 14:10:04

标签: python django pandas matplotlib

尝试使用pickle打开views.py中的.sav文件。 但是给我一个错误。

视图.py:

def result_india(request):
    model = pickle.load(open('finalmodel.sav', 'rb'),
                        encoding='latin1')
    ans = model.piechart()
    return render(request, 'result_india.html', {'ans': ans})

网址:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.home ),
    path('result_india/', views.result_india, name = 'result_india')
]

另外,我的原始 py 文件中有一个函数,我尝试在我的 views.py 中访问该函数。

功能:

def piechart():
    vaccines = ['Pfizer', 'Moderna', 'Oxford/AstraZeneca', 'CNBG', 'Covaxin', 'Sinopharm', 'Sinovac', 'Sputnik V']
    data = [sum_pfizer, sum_moderna, sum_oxford, sum_cnbg, sum_covaxin, sum_sinopharm, sum_sinovac, sum_sputnik]
    fig = plt.figure(figsize=(8, 8))
    plt.pie(data, labels=vaccines, rotatelabels=90)
    piechart = plt.show()
    return piechart
piechart()

完全错误:

UnicodeDecodeError at /result_india/

'utf-8' codec can't decode byte 0x81 in position 5: invalid start byte

Request Method:     GET
Request URL:    http://127.0.0.1:8000/result_india/
Django Version:     3.1.5
Exception Type:     UnicodeDecodeError
Exception Value:    

'utf-8' codec can't decode byte 0x81 in position 5: invalid start byte

Unicode error hint

The string that could not be encoded/decoded was: ffff4�@

0 个答案:

没有答案
相关问题