部署python程序到google app engine
一、gae的部署需要python2.X。于是我的電腦中就不得不又安裝了一個python2.7版。為了保證gae訪問的是正確的python版本,需要打開Google App Engine Launcher后,選擇菜單Edit->Preference修改python解釋器的路徑。
二、部署demo應(yīng)用
選擇菜單File->Add demo Application->python->guestbook可以創(chuàng)建一個demo應(yīng)用,通過運行demo應(yīng)用可以了解GAE的開發(fā)方法。
可惜的是,初次部署完guestbook后,運行會出錯。打開Logs會提示錯誤信息:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinal not in range(128)
Google搜索后發(fā)現(xiàn)原來是python 2.7的庫文件Lib/mimetypes.py存在bug.解決辦法參照
這里修改。行前標(biāo)記+的是需要新增的內(nèi)容,行前標(biāo)記-的是要刪除的內(nèi)容。保存退出后,再運行g(shù)uestbook就沒問題了。注意+from itertools import count這一行不要漏掉了。

三、本地調(diào)試Google App Engine應(yīng)用
錯誤"from google.appengine.api import urlfetch
ImportError: No module named google.appengine.api"。這是因為環(huán)境變量沒有設(shè)置正確。
在環(huán)境變量增加一條PythonPath=“your google app engine path”

錯誤No api proxy found for service "urlfetch"
本地調(diào)試urlfetch調(diào)用時,會遇到這種錯誤。解決辦法
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())
如果需要調(diào)試其他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())
調(diào)試gae應(yīng)用程序,也可以考慮使用在線python調(diào)試環(huán)境http://py-ide-online.appspot.com/
或者使用Google提供的unittest功能。可以參考官網(wǎng)文檔
這里。
python ImportError: No module named yaml錯誤
我的運行環(huán)境是win7 64位,本想使用easy_install pyyaml來安裝,結(jié)果沒找到。
只好從
官網(wǎng)下載 pyyaml源碼,然后執(zhí)行:python setup.py --without-libyaml install重新編譯并安裝。