在跟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. csv 文件用Excel打开乱码

    最近在做一个上传的功能,记录下自己的感受. 刚开始我用的是excel上传:但是发现客户服务器有用64位的,使用的时候程序会报错: 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0” ...

  2. 错误集:js解析jQuery.post返回的xml之Could not find action or result

    js里用jQuery.post去后台查询数据,返回的是xml格式的数据流. js代码: var params = ""; params = encodeURI(params); v ...

  3. 《Android深度探索HAL与驱动开发》第三章阅读心得

    Git是Linux内核代码对源代码进行管理的软件,他的各方面要优与其他同类的源代码管理软件. 安装Git后,查看Git文档在Linux下可以直接使用man命令看指令的帮助文档.安装git-doc后会安 ...

  4. 文件权限及特殊权限管理SUID、SGID和Sticky

    文件权限应用模型: 进程的发起者:     进程属主 进程的属组:      进程属组 进程的属主,是否与文件的属主相同,如果相同,进程则以文件属主的权限来访问文件:否则进程的属主所属的组,其中之一是 ...

  5. MATLAB 绘图时的相关心得

    matlab中如何调整legend的位置? legend('sinx',-1); %----位于图形框外面-----------------------legend('sinx',0);------- ...

  6. Pyhton的发展历程

    Python的由来 在1989年12月时,吉多·范罗苏姆——龟叔,想寻找一门“课余”编程项目来打发圣诞节前后的时间.Guido决定为当时正构思的一个新的脚本语言写一个解释器,它是ABC语言(教学语言. ...

  7. TOMCAT 无法安装P7B格式的证书

    背景:通过按以下链接的方式生成了CSR文件,并申请到P7B格式的证书 现象:TOMCAT安装该证书时,要求输入Keystore key, 但是P7B证书自身并不携带私钥.导致无法通过TOMCAT安装该 ...

  8. Mysql-cluster7.5

    Data nodes: shell> rpm -Uhv mysql-cluster-community-data-node-7.5.5-1.1.el7.x86_64.rpm SQL nodes: ...

  9. Linux系统安装之U盘引导

    折腾了一天,终于把系统安装上去了,心里那个苦啊. 参考:http://blog.csdn.net/avilifans/article/details/13768139 安装步骤如下: 第一步:Ultr ...

  10. [综] Sparse Representation 稀疏表示 压缩感知

    稀疏表示 分为 2个过程:1. 获得字典(训练优化字典:直接给出字典),其中字典学习又分为2个步骤:Sparse Coding和Dictionary Update:2. 用得到超完备字典后,对测试数据 ...