1、问题描述

今天在升级Ubuntu到14.04,使用命令行启动软件更新器,进行版本升级,结果开始升级就异常退出了,具体打印如下:

$update-manager -d
正在检查新版 Ubuntu
使用 'trusty.tar.gz.gpg' 对 'trusty.tar.gz' 进行验证
正在提取 'trusty.tar.gz'
Traceback (most recent call last):
File "/tmp/ubuntu-release-upgrader-r_0oij/trusty", line , in <module>
sys.exit(main())
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/DistUpgradeMain.py", line , in main
if app.run():
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/DistUpgradeController.py", line , in run
return self.fullUpgrade()
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/DistUpgradeController.py", line , in fullUpgrade
if not self.updateSourcesList():
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/DistUpgradeController.py", line , in updateSourcesList
if not self.rewriteSourcesList(mirror_check=True):
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/DistUpgradeController.py", line , in rewriteSourcesList
logging.debug("entry '%s' was disabled (unknown mirror)" % get_string_with_no_auth_from_source_entry(entry))
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/utils.py", line , in get_string_with_no_auth_from_source_entry
return str(tmp)
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/sourceslist.py", line , in __str__
return self.str().strip()
File "/tmp/ubuntu-release-upgrader-r_0oij/DistUpgrade/sourceslist.py", line , in str
line += u" #%s" % self.comment
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)

2、方案探索

主要错误是上面最后一行的Unicode解码问题,网上搜索说是读取文件时使用的编码默认时ascii而不是utf8,导致的错误;原始资料路径为:

http://blog.csdn.net/vincent_czz/article/details/7719012

在代码中加上如下几句即可。

import sys
reload(sys)
sys.setdefaultencoding('utf8')

http://docs.python.org/howto/unicode.html 这个是python的unicode编码API文档,英文好的同学可以看一下,加深理解。

3、解决方案

3.1 拷贝临时数据到本地

根据上面错误提示,拷贝升级包代码到本地,并修改权限为自己可以编辑

$sudo cp -R /tmp/ubuntu-release-upgrader-r_0oij ./upgrade
$sudo chown qunengrong:qunengrong upgrade/ -R

3.2 修正读取文件的代码

打开上面报错的文件,如DistUpgradeMain.py,进行编辑并保存;

## 原来为下面行
#import sys
## 改为下面的3行
import sys
reload(sys)
sys.setdefaultencoding('utf8')

3.3 手动启动升级

为了安全和防止升级过程被打断,建议提交到后台执行,如使用nohup,输入密码后按CTRL+Z终端,然后输入bg命令让其后台执行:

$nohup sudo ./trusty
nohup: 忽略输入并把输出追加到"nohup.out"
[sudo] password for qunengrong: ^Z
[]+ 已停止 nohup sudo ./trusty
qunengrong@qunengrong-Studio- ~/tests/apt/upgrade
$bg
[]+ nohup sudo ./trusty &

已经可以正常升级了,如下:

【Python】【解决】UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)的更多相关文章

  1. 解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128

    今天做网页到了测试和数据库交互的地方,其中HTML和数据库都是设置成utf-8格式编码,插入到数据库中是正确的,但是当读取出来的时候就会出错,原因就是python的str默认是ascii编码,和uni ...

  2. HTMLTestRunner解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)

    其中HTML和数据库都是设置成utf-8格式编码,插入到数据库中是正确的,但是当读取出来的时候就会出错,原因就是python的str默认是ascii编码,和unicode编码冲突,就会报这个标题错误. ...

  3. 解决UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 12: ordinal not in range(128)的编码问题

    当我在运行一个基于scrapy的爬虫时出现UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 12: ordina ...

  4. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

    问题分析:错误提示中的“ordinal not in range(128)”,意思是,字符不在128范围内,即说明不是普通的ASCII字符,超出处理能力了. import sys print u'系统 ...

  5. 解决UnicodeDecodeError: 'ascii' codec can't decode byte 0xcf in position 7: ordinal not in range(128)

    在Windows下同时装了Python2和Python3,但是在使用命令给pip更新的时候,出现了以下错误: 解决办法:修改mimetypes.py文件,路径位于python的安装路径下的Lib\mi ...

  6. python 错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)

    参照:http://www.runoob.com/django/django-form.html 做了个表单提交和回显,但是报了以上错误 查资料发现是 python从request取值的是unicod ...

  7. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)

    对于写python的人来说,这个异常一点不陌生,只要涉及到中文字符串的操作,一不小心就会出错.关于这个问题的解释,找到一篇好文,分享一下. 原文地址:https://blog.csdn.net/u01 ...

  8. [错误处理]UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

    Stackoverflow 回答: 将byte类型转化:byte_string.decode('utf-8') Jinja2 is using Unicode internally which mea ...

  9. UnicodeDecodeError:'ascii' codec can't decode byte 0xe5 in position 89: ordinal not in range(128)

    环境python2,在出现该错误的python文件,增加: import sys reload(sys) sys.setdefaultencoding('utf8') 重新运行,不再报错

随机推荐

  1. Android日志服务 记录日志

    转: http://easion-zms.iteye.com/blog/981568 import java.io.BufferedReader; import java.io.File; impor ...

  2. 千万不要误用 java 中的 HashCode 方法

    刚才debug追堆栈的时候发现一个很奇怪的问题 我用IE8和Google的浏览器访问同一个地址 Action的 scope="session" 也设置了 而且两个浏览器提交的参数m ...

  3. spark对于elasticsearch里的复杂类型支持

    IP,直接在case class里用string, 可以考虑先用其它程序生成相关的mapping,然后再去用spark填充数据

  4. JSP 使用

    JSP教程: http://www.w3cschool.cc/jsp/jsp-tutorial.html jsp语法: 任何语言都有自己的语法,JAVA中有,JSP虽然是在JAVA上的一种应用,但是依 ...

  5. 利用dedecms autoindex让文章列表加上序列号

    有些时候我们在制作模板的需要在文章标题前面加上序列号,可以通过织梦自带的autoindex属性来实现,实现方法很简单,只需要在序号递增的地方加上 这段代码就行,[field:global runphp ...

  6. .Net开源工作流Roadflow的使用与集成(转)

    序言 最近公司要整理公司内部oa系统,需要使用到工作流,所以就开始了开源工作流挑选,使用,到集成到公司内部系统的工作. 首先在网上搜了文档,自己也有补充,整理啦国内几款工作流的比较,由于没有个个击破式 ...

  7. 学习Linux下的IP地址地理位置信息显示工具nali

    首先详细教程已经有前辈做了详细的安装和使用介绍,本人只是参照学习和记录下自己的实际操做. 本文参考档:http://www.cnblogs.com/mchina/archive/2012/12/24/ ...

  8. CDNJS:使用JavaScript CDN加速网站载入速度

    先介绍一下: 内容传递网络(CDN)或者叫内容分发网络,他的作用是给不同区域的访客以其最快的网速.比如,你的网站是开在美国的,但很多访客来自中国,无疑他们会觉得速度很慢,那么,怎么为他们提速呢?简单来 ...

  9. Matlab图像处理入门

    1. Matlab基础 1.1     数据格式 Matlab默认的数据格式为双精度浮点数的矩阵或数组,同时支持其它数据类型.Matlab将单变量看作1´1的数组.Matlab支持的数据类型如下: 索 ...

  10. 关于js函数中的异步编程

    大家都说js 是单线程的应用,但是随着技术的发展,js的发展已经不仅仅局限于单线程了.因为现在很多都是异步了,所谓的异步,就是类似于ajax,写了一个回调函数,当我的服务还在这个地方的时候,等着他去排 ...