huyutian

他强由他强,清风拂山岗;他横由他横,明月照大江。他自狠来他自恶,我自一口真气足

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  20 随笔 :: 47 文章 :: 22 评论 :: 0 Trackbacks
部署python程序到google app engine
一、gae的部署需要python2.X。于是我的电脑中就不得不又安装了一个python2.7版。为了保证gae访问的是正确的python版本,需要打开Google App Engine Launcher后,选择菜单Edit->Preference修改python解释器的路径。
二、部署demo应用
选择菜单File->Add demo Application->python->guestbook可以创建一个demo应用,通过运行demo应用可以了解GAE的开发方法。
可惜的是,初次部署完guestbook后,运行会出错。打开Logs会提示错误信息:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)

Google搜索后发现原来是python 2.7的库文件Lib/mimetypes.py存在bug.解决办法参照这里修改。行前标记+的是需要新增的内容,行前标记-的是要删除的内容。保存退出后,再运行guestbook就没问题了。注意+from itertools import count这一行不要漏掉了。
三、本地调试Google App Engine应用
错误"from google.appengine.api import urlfetch
ImportError: No module named google.appengine.api"。这是因为环境变量没有设置正确。
在环境变量增加一条PythonPath=“your google app engine path”

错误No api proxy found for service "urlfetch"
本地调试urlfetch调用时,会遇到这种错误。解决办法
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import urlfetch_stub

apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() 
apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub())
如果需要调试其他gae API(比如mail,datastore),可以添加以下代码
from google.appengine.api import datastore_file_stub 
from google.appengine.api import mail_stub 
from google3.apphosting.api import user_service_stub 
apiproxy_stub_map.apiproxy.RegisterStub('user', 
user_service_stub.UserServiceStub()) 
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', 
  datastore_file_stub.DatastoreFileStub('your_app_id', '/dev/null', '/ 
dev/null')) 
apiproxy_stub_map.apiproxy.RegisterStub('mail', 
mail_stub.MailServiceStub())

调试gae应用程序,也可以考虑使用在线python调试环境http://py-ide-online.appspot.com/
或者使用Google提供的unittest功能。可以参考官网文档这里

python ImportError: No module named yaml错误
我的运行环境是win7 64位,本想使用easy_install pyyaml来安装,结果没找到。
只好从官网下载 pyyaml源码,然后执行:python setup.py --without-libyaml install重新编译并安装。
posted on 2014-02-15 21:12 胡雨田 阅读(646) 评论(0)  编辑 收藏 引用 所属分类: 网络编程编程技巧

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理