在跟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. C++ 虚函数,纯虚函数的一些问题

    #include <iostream> using namespace std; #define cendl cout << endl; class AA{//这是一个纯虚函数 ...

  2. [读书笔记]Java之动态分派

    以下内容来自周志明的<深入理解Java虚拟机>. 前一篇说了静态分派和重载有关,现在的动态分派就和覆盖Override有关了. 先看代码: public class DynamicDisp ...

  3. 4.Rabbits and Recurrence Relations

    Problem A sequence is an ordered collection of objects (usually numbers), which are allowed to repea ...

  4. C# 二维数组相关知识记录

    //初始化一个数组 , ] { { , }, { , }, { , }, { , }, { , } }; //查某个字段的长度 print(name.GetLength()); //获得第一个字段的长 ...

  5. linux下软件安装与升级

    待续 sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade

  6. mysql 联合索引和唯一索引

    一般来说.如果有where a=? and b=? and c=? 的语句. 如果表也有DML, 我一般只在a 上建索引.  这也是代价平衡的结果. 一方面 只在a 上建索引那么是 index ran ...

  7. 王爽 <<汇编 语言>> 13.6 BIOS中断例程应用

    ;名称:ILOVEU程序 ;使用BIOS提供的中断例程 assume cs:code code segment main: ;显示背景22*80 ;dh中放行号 ;dl中放列号 bibi: push ...

  8. js动态更改对象属性值的方法

    下面代码,替换属性名称包含date的属性中的T为空格. for (var o in data) {                        //console.info(eval("d ...

  9. Asp.net MVC 的八个扩展点

    http://www.cnblogs.com/richieyang/p/5180939.html MVC模型以低耦合.可重用.可维护性高等众多优点已逐渐代替了WebForm模型.能够灵活使用MVC提供 ...

  10. python之正则表达式

    1) 用管道符号(|)匹配多个正则表达式 举例 at | home     匹配 at, home 2) 匹配任意一个单个的字符(.) 举例 f.o  匹配在"f"和"o ...