在跟Web Development,要在Google App Engine上写作业,出师不利,遇到以下bug:

2014-05-06 16:14:17 Running command: "['C:\\Python27\\python.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', 'E:\\GoogleAppEngine\\hello_udacity']"
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 82, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 78, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 33, in <module>
from google.appengine.tools.devappserver2.admin import admin_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\admin_server.py", line 29, in <module>
from google.appengine.tools.devappserver2.admin import console
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\console.py", line 22, in <module>
from google.appengine.tools.devappserver2 import module
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py", line 49, in <module>
from google.appengine.tools.devappserver2 import gcs_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\gcs_server.py", line 29, in <module>
from google.appengine.tools.devappserver2 import wsgi_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\wsgi_server.py", line 31, in <module>
from cherrypy import wsgiserver
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\__init__.py", line 70, in <module>
from cherrypy import _cptools
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\_cptools.py", line 245, in <module>
from cherrypy.lib import cptools, encoding, auth, static, jsontools
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\lib\static.py", line 7, in <module>
mimetypes.init()
File "C:\Python27\lib\mimetypes.py", line 358, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
for subkeyname in enum_types(hkcr):
File "C:\Python27\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
2014-05-06 16:14:25 (Process exited with code 1)

经查,此为Python2.7的一个bug。在读取windows注册表中的文件类型列表的时候,Python默认读到的数据为Latin-1编码,因此遇上中文、俄文等等其他类型的编码统统会出错。

闯祸的软件会在注册表里填写恼人的不规范的文件类型。俄文的一个典型是QuickTime,而中文则是阿里旺旺

On Windows, mimetypes initialization reads the list of MIME types from the Windows registry. It assumes that all characters are Latin-1 encoded, and fails when it's not the case, with the following exception:

Traceback (most recent call last):
File "mttest.py", line 3, in <module>
mimetypes.init()
File "c:\Python27\lib\mimetypes.py", line 355, in init
db.read_windows_registry()
File "c:\Python27\lib\mimetypes.py", line 260, in read_windows_registry
for ctype in enum_types(mimedb):
File "c:\Python27\lib\mimetypes.py", line 250, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128) This can be reproduced, for example, on a Russian Windows XP installation which has QuickTime installed (QuickTime creates the non-Latin entries in the registry). The following line causes the exception to happen: import mimetypes; mimetypes.init()

解决办法各种各样,下面说2个:

1. 修改mimetypes.py(有很多种修改办法,这里贴其中一种,添加如#<--标识的2行即可)

Alternative temporary solution
def enum_types(mimedb):
....
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass
except Exception: #<--
pass #<--
else:
yield ctype

或者:

2. 在Python安装目录下的Lib\site-packages文件夹创建sitecustomize.py文件,内容为:

import sys
sys.setdefaultencoding('cp936')
此外还可以清理注册表中HKEY_CLASSES_ROOT下所有非ascii字符的键。

不用费那劲了,直接下载修正的mimetypes.py覆盖原文件即可。

http://yunpan.cn/QiZRib89b5h8X (提取码:eacf)

链接:http://pan.baidu.com/share/link?shareid=4126899422&uk=1879334133 密码:uhcw

完。

Google App Engine, Python2.7的UnicodeDecodeError bug的更多相关文章

  1. Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案

    #Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案   ##问题描述 使用Python2.7.x运行GAE时有时会报这个错误 ```py ...

  2. 如何架设部署V2EX社区/论坛(Google App Engine版)

    1.What's V2EX? 关于这个问题,我们可以看看其作者Livid早期自己的V2EX社区的介绍: What's V2EX? 这是很多人都问过的问题,而我一直都没有做出一个明确的解答.因为我实在觉 ...

  3. [Ubuntu] Linux下使用google app engine,无法打开https网站的解决方法

    为什么这里写的是 google app engine?原因我就不解释了.步骤如下: 1)安装证书导入工具:$ sudo apt-get install libnss3-tools 2)导入CA.crt ...

  4. 介绍Google App Engine

    Google App Engine是一个网络应用托管服务(web application hosting service).所谓网络应用(By web application),我们的意思的可以通过网 ...

  5. Google App Engine Deployment 相关问题

    1.GAE instance上传成功之后可以正常运行的情况下.在Google账户中“关联的应用和网站”,撤销Google App Engine appcfg对Google账户的访问权限. 再次上传时, ...

  6. Google App Engine 学习和实践

    这个周末玩了玩Google App Engine,随手写点东西,算是学习笔记吧.不当之处,请多多指正. 作者:liigo,2009/04/26夜,大连 原创链接:http://blog.csdn.ne ...

  7. PaaS平台– Google App Engine的开源实现AppScale环境搭建

    搭建好开发环境介绍: 硬件平台:HP Z800 工作站  内存:24GB      硬盘:1TB 虚拟化环境:XenServer 6.2.0 VM1:Ubuntu 12.04 amd64 server ...

  8. 使用Google App Engine开始新的网站开发学习

    继长时间的迷茫后,我发现还是回归php网站开发更适合我,或者没有那么深刻,但至少要做点事情.不知道以后将从事什么样的工作,但现在找点事情做还是很好的.所以,为了激发我学习的热情,我在网上搜了一下免费云 ...

  9. 给Eclipse安装Google app engine插件

    1.一般的做法: 参考:https://developers.google.com/eclipse/docs/install-eclipse-4.3 2. 因为 上面的做法一直没有成功,改为下载离线包 ...

随机推荐

  1. Default Title

    測試的標誌 代表意義 1. 關於某個檔名的『檔案類型』判斷,如 test -e filename 表示存在否 -e 該『檔名』是否存在?(常用) -f 該『檔名』是否存在且為檔案(file)?(常用) ...

  2. Spring可以将简单的组件配置

    这次听了老师的课程,觉得还是需要更加集中的去把各种题进行一个分类吧,然后有针对的去准备,虽然据说这一块在面试中也不容易考到,但是毕竟是难点,还是需要好好准备一下的.因为在dp这个方面,我算是一个比较新 ...

  3. Python实例2

    2.企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万之间 ...

  4. caching redirect views leads to memory leak (Spring 3.1)

    在Spring 3.1以及以下版本使用org.springframework.web.servlet.view.UrlBasedViewResolver + cache(如下配置),在会出现任意种re ...

  5. PHP 登录

    <?php// 本类由系统自动生成,仅供测试用途namespace Home\Controller;use Think\Controller;use Org\Util\Rbac; use Thi ...

  6. Java数据类型、变量、运算符、语句。

    数据类型:整型 int long short byte小数 double float 字符 char 转义字符:\'(单引号字符) \\(反斜杠字符) \n(换行) \r(回车) \t(水平制表符,相 ...

  7. CE 内存申请

    char ch_ReadByte='H'; char *ptr_OneLineData; unsigned ); if ((ptr_OneLineData = (char *)malloc(bufsi ...

  8. phpstorm version 2016.2 License Server激活

    phpstorm version 2016.2 License Server激活 安装后,在激活的时候选择 license server; 输入如下地址激活: http://jetbrains.ten ...

  9. 「LINUX资料」Samba服务器(二)

  10. linux目录结构详细介绍

    目录1.树状目录结构图2./目录3./etc/目录4./usr/目录5./var/目录6./proc/目录7./dev/目录 该文章主要来自于网络进行整理.目录结构参考地址:http://www.hu ...