今天尝试了下Google App Engine,免费的东西就是爽啊。
(1)https://appengine.google.com/ 新建一个应用。
(2)下载GAE SDK for Python并安装。 http://code.google.com/appengine/downloads.html
(3)打开GAE Launcher,新建一个应用。
(4)打开项目保存目录,可以看到自动生成项目初始化文件:app.yaml,index.yaml,main.py。
在main.py中添加自己的代码。GAE Python使用的是标准的Python语法,所以不用担心语法会有所不同。
在GAE Launcher中启动项目red-ice。然后就可以在本地用http://127.0.0.1:8081(注意:你的可能是8080)访问这个应用了。
(5)如何将应用部署到GAE服务器上?看到GAE Launcher上的Deploy按钮了吧?
点击这个按钮,按照提示输入你的谷歌账户密码,然后项目文件就自动被上传到GAE服务器上了。
当消息窗口提示“You can close this window now.”时,说明已经部署完毕了。
就可以使用http://red-ice.appspot.com/来访问我们的应用了。
我在我的red-ice应用里简单地实现了我博客首页的反向代理。源码如下:
#!/usr/bin/env python # # Copyright 2007 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from google.appengine.ext import webapp from google.appengine.ext.webapp import util import re import gzip from StringIO import StringIO import urllib2 import urllib from urlparse import urljoin DEBUG = True class MainHandler(webapp.RequestHandler): def get(self): down = DownLoad() self.response.out.write(down.get('http://www.redicecn.com')) class DownLoad: def get(self, url, num_retries=2): opener = urllib2.build_opener() headers = {'User-agent': 'Mozilla/5.0', 'Accept-encoding': 'gzip', 'Referrer': url} try: response = opener.open(urllib2.Request(url, None, headers)) content = response.read() if response.headers.get('content-encoding') == 'gzip': # data came back gzip-compressed so decompress it content = gzip.GzipFile(fileobj=StringIO(content)).read() if not isinstance(content,unicode): content = unicode(content,'gbk') content = re.compile(r'''(href|src)=['"](.*?)['"]''',re.DOTALL | re.IGNORECASE).sub(lambda m : m.groups()[0]+'="'+urljoin(url,m.groups()[1])+'"',content) except Exception, e: # so many kinds of errors are possible here so just catch them all if num_retries > 0: content = self.get(url, num_retries - 1) else: content = '' return content def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) util.run_wsgi_app(application) if __name__ == '__main__': main()
效果如下:http://red-ice.appspot.com/
关于GAE的更多资料请访问:http://code.google.com/appengine/
呵呵,谢谢
VaTG790i.最好的<a href=http://www.kyfei.com>网站推广软件</a>,
非常好
....................
;ui;普i;uighur;ui;ui;个
在unix网络编程中看到了关于TCP/IP的一些内容,我感觉还是写的不够。正在下载中,一定
下载地址呢