UnicodeDecodeError: 'utf-8' codec can't decode byte
for line in open('u.item'):
#read each line
whenever I run this code it gives the following error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 2892: invalid continuation byte
I tried to solve this and add an extra parameter in open(), the code looks like;
for line in open('u.item', encoding='utf-8'):
#read each line
But again it gives the same error. what should I do then! Please help.
解决方案:
As suggested by Mark Ransom, I found the right encoding for that problem.
The encoding was "ISO-8859-1", so replacing open("u.item", encoding="utf-8") with open('u.item', encoding = "ISO-8859-1") will solve the problem.
UnicodeDecodeError: 'utf-8' codec can't decode byte的更多相关文章
- flask+sqlite3+echarts2+ajax数据可视化报错:UnicodeDecodeError: 'utf8' codec can't decode byte解决方法
flask+sqlite3+echarts2+ajax数据可视化报错: UnicodeDecodeError: 'utf8' codec can't decode byte 解决方法: 将 py文件和 ...
- Python报错UnicodeDecodeError: ascii codec can t decode byte 0xe0 ...解决方法
用命令(python setup.py install)安装webpy时候总是报错 在网上搜索到的解决方法如下: 1. 这是Python 2 mimetypes的bug 2. 需要将Python2.7 ...
- python2.7 报错(UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128))
报错: 原来用的python3.5版本后来改为2.7出现了这个错误里面的中文无法显示 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 ...
- UnicodeDecodeError: 'utf8' codec can't decode byte 0xce in position 47: invalid continuation byte
- Requests库上传文件时UnicodeDecodeError: 'ascii' codec can't decode byte错误解析
在使用Request上传文件的时候碰到如下错误提示: 2013-12-20 20:51:09,235 __main__ ERROR 'ascii' codec can't decode byte 0x ...
- 【Python】【解决】UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)
1.问题描述 今天在升级Ubuntu到14.04,使用命令行启动软件更新器,进行版本升级,结果开始升级就异常退出了,具体打印如下: $update-manager -d 正在检查新版 Ubuntu 使 ...
- setuptools,pip,install,UnicodeDecodeError: 'ascii' codec can't decode byte.原因和解决方案
昨天重装Python2.7.6时,为了安装第三方库,我去下pip.为了装pip,又得先装 ez_setup.py.结果装ez_setup时,遇到了问题,报错: UnicodeDecodeError: ...
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ordinal not in range(128) 解决办法
最近在用Python处理中文字符串时,报出了如下错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 0: ...
- 安装mysql-python报错:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 65: ordinal not in range(128)
安装mysql-python报错: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 65: ordinal n ...
- Python HTMLTestRunner生成网页自动化测试报告时中文编码报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6
1. 由于使用Python Selenium做网页自动化测试时,有截取网页上的中文信息保存到测试结果中,最终出现编码错误如下: File "D:/PycharmProjects/AutoTe ...
随机推荐
- dcm4che,WADO相关
关于 dcm4che WADO WADO:Web Access to DICOM Objects dcm4che 是一个为医疗保健企业的开源应用程序和工具集合.这些应用程序已经开发了Java编程语言的 ...
- VMware vSphere 5.1 群集深入解析(一)
http://virtualbox.blog.51cto.com/531002/1168293 VMware vSphere 5.1 Clustering Deepdive HA.DRS.Storag ...
- 转:nginx模块开发——handler(一)
handler模块简介 相信大家在看了前一章的模块概述以后,都对nginx的模块有了一个基本的认识.基本上作为第三方开发者最可能开发的就是三种类型的模块,即handler,filter和load-ba ...
- WIP 001 - design the applicant screen
In this item, you only need to design the screen
- JDK5.0 特性-线程 Condition
来自:http://www.cnblogs.com/taven/archive/2011/12/17/2291471.html import java.util.concurrent.Executor ...
- 【Linux】生成任意大小的文件
有时候,我们需要生成指定大小的随机文件,比如在学习过程中使用的测试文件. 命令: Linux:/qinys # dd if=/dev/zero of=tmp.data bs=500k count=1 ...
- 使用springMVC和Jquery实现JSONP
JSONP这个东东是啥我就不写了,直接贴实现的代码 JAVA代码: /** * * 查询用户是否已经提交认证获取已经是认证会员 * * 使用spring mvc的直接返回string会遇到分号转义后字 ...
- Naive Bayes Classifier 朴素贝叶斯分类器
贝叶斯分类器的分类 根据实际处理的数据类型, 可以分为离散型贝叶斯分类器和连续型贝叶斯分类器, 这两种类型的分类器, 使用的计算方式是不一样的. 贝叶斯公式 首先看一下贝叶斯公式 $ P\left ( ...
- Arduino和C51开发LCD1602显示屏
技术:51单片机.Arduino.LCD1602 概述 本文介绍了LCD1602显示屏,并在LCD1602上显示字符串,对LCD1602常见的问题的解决和开发方法也做了简单介绍. 详细 代码下载: ...
- BOM介绍
BOM 浏览器对象模型 BOM (Browser Object Model,浏览器对象模型)提供了通过 JavaScript 访问和控制浏览器窗口(window).显示器(screen)与浏览历史(h ...