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. Struts2 自定义Result

    注意:我只要是解决自定义返回Json 和异常处理问题 新建一个类 AjaxResult   继承 StrutsResultSupport 看看代码吧 public class AjaxResult e ...

  2. yum被锁Another app is currently holding the yum lock; waiting for it to exit...

    可能是系统自动升级正在运行,yum在锁定状态中. 可以通过强制关掉yum进程: #rm -f /var/run/yum.pid 然后就可以使用yum了.

  3. 我对 impress.js 源码的理解

    源码看了两天,删掉了一些优化,和对 ipad 的支持,仅研究了其核心功能的实现,作以下记录. HTML 结构如下: <!doctype html> <html lang=" ...

  4. 面试题52:缺少i的乘积数组

    vector<int> multiply(const vector<int>& A) { int len = A.size(); vector<); result ...

  5. PDP 有多种定义,具体哪一种还需研究!!!!

    PDP (用户面进行隧道转发的信息的保存协议) 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! 即PDP上下文,保存用户面进行隧道转发的所有信息,包括RNC/GGSN的 ...

  6. 我用的/etc/vimrc

    " 映射非数字/字母键, 如:ctrl,shift, alt, home,end,功能键F1~F12, 要把这些键用尖括号括起来!如: map <F3> :NERDTree< ...

  7. 简论:int i = 0

    int i =0; 或许这就是i和0的缘分吧...

  8. iOS 用instancetype代替id作返回类型有什么好处?

    2014-07-07更新:苹果在iOS 8中全面使用instancetype代替id Steven Fisher:只要一个类返回自身的实例,用instancetype就有好处. @interface ...

  9. ruby : Exception Notification

    https://github.com/smartinez87/exception_notification#sections Add the following line to your applic ...

  10. 多层神经网络与C++实现

    BP理论部分参考:http://blog.csdn.net/itplus/article/details/11022243 参考http://www.cnblogs.com/ronny/p/ann_0 ...