<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>可可熊的窝 &#187; gae</title>
	<atom:link href="http://cocobear.info/blog/tag/gae/feed/" rel="self" type="application/rss+xml" />
	<link>http://cocobear.info/blog</link>
	<description>K.I.S.S</description>
	<lastBuildDate>Tue, 17 Aug 2010 10:26:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>GAE上使用PyFetion做一个应用</title>
		<link>http://cocobear.info/blog/2009/12/15/app-use-pyfetion-on-gae/</link>
		<comments>http://cocobear.info/blog/2009/12/15/app-use-pyfetion-on-gae/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 06:22:14 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[编程相关]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[PyFetion]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=759</guid>
		<description><![CDATA[GAE上有一个cron jobs的功能，类似于Linux下的crontab，可以实现在指定规则的时间里去运行程序。利用这个功能和飞信的短信功能就完成一些简单的小应用，比如天气预报，服务器监控，股票大盘实时行情提醒等等。 拿服务器监控来说，我们先注册一个GAE账户，然后创建一个Application，下载一份GAE 的SDK，接下来就写代码了。 (以上过程请自行google之) monitor.py: PYTHON: #!/usr/bin/env python # -*- coding: utf-8 -*- #MIT License #By : cocobear.cn@gmail.com # &#160; from google.appengine.api import urlfetch from PyFetion import * &#160; def get&#40;&#41;: &#160; &#160; print&#40;'&#60;html&#62;&#60;body&#62;'&#41; &#160; &#160; url = 'http://61.236.244.162' &#160; &#160; result = urlfetch.fetch&#40;url&#41; &#160; &#160; if result.status_code == 200: &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>上有一个cron jobs的功能，类似于Linux下的crontab，可以实现在指定规则的时间里去运行程序。利用这个功能和飞信的短信功能就完成一些简单的小应用，比如天气预报，服务器监控，股票大盘实时行情提醒等等。</p>
<p>拿服务器监控来说，我们先注册一个<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>账户，然后创建一个Application，下载一份<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a> 的SDK，接下来就写代码了。<br />
(以上过程请自行google之)</p>
<p>monitor.py:</p>
<div class="syntax_hilite"><span class="langName"><a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">PYTHON</a>:</span>
<div id="python-6">
<div class="python" style="font-family:monospace;">
<ol>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7f7f7f; font-style: italic;">#!/usr/bin/env <a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">python</a></span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7f7f7f; font-style: italic;"># -*- coding: utf-8 -*-</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7f7f7f; font-style: italic;">#MIT License</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7f7f7f; font-style: italic;">#By : cocobear.cn@gmail.com</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7f7f7f; font-style: italic;">#</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0088ff;font-weight:bold;">from</span> google.<span style="color: white;">appengine</span>.<span style="color: white;">api</span> <span style="color: #0088ff;font-weight:bold;">import</span> urlfetch</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0088ff;font-weight:bold;">from</span> <a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a> <span style="color: #0088ff;font-weight:bold;">import</span> <span style="color: #993399;">*</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0088ff;font-weight:bold;">def</span> get<span style="color: white;">&#40;</span><span style="color: white;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">print</span><span style="color: white;">&#40;</span><span style="color: #b7c274;">'&lt;html&gt;&lt;body&gt;'</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; url = <span style="color: #b7c274;">'http://61.236.244.162'</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; result = urlfetch.<span style="color: white;">fetch</span><span style="color: white;">&#40;</span>url<span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">if</span> result.<span style="color: white;">status_code</span> == <span style="color: #00baff;color:#800000;">200</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">print</span><span style="color: white;">&#40;</span><span style="color: #b7c274;">'OK'</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">else</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; fetion = <a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a><span style="color: white;">&#40;</span><span style="color: #b7c274;">'136xxxx'</span>,<span style="color: #b7c274;">'123456'</span>,<span style="color: #b7c274;">'HTTP'</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; i = <span style="color: #00baff;color:#800000;">0</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">while</span> <span style="color: #ff7fff;">True</span>:</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">try</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fetion.<span style="color: white;">login</span><span style="color: white;">&#40;</span>FetionOnline<span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fetion.<span style="color: white;">send_sms</span><span style="color: white;">&#40;</span><span style="color: #b7c274;">'服务器掉了!'</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fetion.<span style="color: white;">logout</span><span style="color: white;">&#40;</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">except</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">if</span> i<span style="color: #993399;">&gt;</span> <span style="color: #00baff;color:#800000;">5</span>:</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">break</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">continue</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">print</span><span style="color: white;">&#40;</span><span style="color: #b7c274;">'&lt;/body&gt;&lt;/html&gt;'</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0088ff;font-weight:bold;">if</span> __name__ == <span style="color: #b7c274;">'__main__'</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; get<span style="color: white;">&#40;</span><span style="color: white;">&#41;</span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>很简单的代码，使用<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>的函数urlfetch.fetch来访问这个地址，如果失败调用<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>来发短信给自己做通知。</p>
<p>app.yaml:</p>
<div class="syntax_hilite"><span class="langName"><a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">PYTHON</a>:</span>
<div id="python-7">
<div class="python" style="font-family:monospace;">
<ol>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">application: pythoning</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">version: <span style="color: #00baff;color:#800000;">1</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">runtime: <a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">python</a></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">api_version: <span style="color: #00baff;color:#800000;">1</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">handlers:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">- url: /console/.<span style="color: #993399;">*</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; script: $PYTHON_LIB/google/appengine/ext/admin</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; login: admin</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">- url: /monitor</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; script: monitor.<span style="color: white;">py</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">- url: /</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; static_files: index.<span style="color: white;">html</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; upload: index.<span style="color: white;">html</span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>这里指定url映射的规则，访问pythoning.appspot.com/monitor就会执行monitor.py脚本。application需要填写你申请<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>应用时的名称，也就是这个二级域名pythoning，version：当前代码的版本。</p>
<p>index.html:</p>
<div class="syntax_hilite"><span class="langName"><a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">PYTHON</a>:</span>
<div id="python-8">
<div class="python" style="font-family:monospace;">
<ol>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">首页你可以做别的事，比如放个人主页，然后把自己域名指过来。</div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>cron.yaml:</p>
<div class="syntax_hilite"><span class="langName"><a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">PYTHON</a>:</span>
<div id="python-9">
<div class="python" style="font-family:monospace;">
<ol>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">cron:</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">- description: watch http server </div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; url: /monitor</div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; schedule: every <span style="color: #00baff;color:#800000;">1</span> minutes</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; timezone: Asia/Shanghai</div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>关键的一个文件，对monitor这个url进行定时执行，这里是每分钟执行一次; 如果你是写天气预报，就可以写为 7:00 every day，每天早上7点发一次天气预报。</p>
<p>写完这些以后，运行命令:<br />
ls demos/test<br />
app.yaml cron.yaml index.html monitor.py <a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>.py<br />
<a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">python</a> appcfg.py update demos/test<br />
把你的代码提交到<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>服务器上，你可以在<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>的后台Cron Jobs看到：</p>
<blockquote><p>/monitor<br />
watch http server	 every 1 minutes (Asia/Shanghai)<br />
2009/12/15 14:06:50 on time Success
</p></blockquote>
<p>在<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>上使用r49版本的<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>，请注释掉from select import select,如果只是像上面做提醒的话最后去掉下面的代码(824行):</p>
<div class="syntax_hilite"><span class="langName"><a href="http://cocobear.info/blog/tag/python/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Python">PYTHON</a>:</span>
<div id="python-10">
<div class="python" style="font-family:monospace;">
<ol>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7fff;">self</span>.<span style="color: white;">get_personal_info</span><span style="color: white;">&#40;</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0088ff;font-weight:bold;">if</span> <span style="color: #0088ff;font-weight:bold;">not</span> <span style="color: #ff7fff;">self</span>.<span style="color: white;">get_contactlist</span><span style="color: white;">&#40;</span><span style="color: white;">&#41;</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; d_print<span style="color: white;">&#40;</span><span style="color: #b7c274;">&quot;get contactlist error&quot;</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">return</span> <span style="color: #ff7fff;">False</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7fff;">self</span>.<span style="color: white;">get</span><span style="color: white;">&#40;</span><span style="color: #b7c274;">&quot;compactlist&quot;</span>,<span style="color: #ff7fff;">self</span>.__uri,<span style="color: #ff7fff;">self</span>.<span style="color: white;">contactlist</span>.<span style="color: white;">keys</span><span style="color: white;">&#40;</span><span style="color: white;">&#41;</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">response = <span style="color: #ff7fff;">self</span>.<span style="color: white;">send</span><span style="color: white;">&#40;</span><span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #23ebc3;">code</span> = <span style="color: #ff7fff;">self</span>.<span style="color: white;">get_code</span><span style="color: white;">&#40;</span>response<span style="color: white;">&#41;</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #0088ff;font-weight:bold;">if</span> <span style="color: #23ebc3;">code</span> <span style="color: #993399;">!</span>= <span style="color: #00baff;color:#800000;">200</span>:</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp; &nbsp; <span style="color: #0088ff;font-weight:bold;">return</span> <span style="color: #ff7fff;">False</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7f7f7f; font-style: italic;">#self.get(&quot;PGGetGroupList&quot;,self.__uri)</span></div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #7f7f7f; font-style: italic;">#response = self.send()</span></div>
</li>
<li style="font-weight: bold; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div>
</li>
<li style="font-weight: normal; vertical-align:top;color:#3A6A8B;">
<div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #ff7fff;">self</span>.<span style="color: white;">get_offline_msg</span><span style="color: white;">&#40;</span><span style="color: white;">&#41;</span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>这里是获得了好友列表，然后给这些好友发一个上线的通知，如果你不想每次提醒的时飞信上的好友都看到你上线，那么就去掉这些，也会加快发送短信的速度。更进一步的优化，你可以去掉TCP通信的相关代码。</p>
<p>ok, 发挥你的想象力，play with <a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a> and <a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cocobear.info/blog/2009/12/15/app-use-pyfetion-on-gae/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>关于PyFetion不能在GAE上使用</title>
		<link>http://cocobear.info/blog/2009/04/25/pyfetion-can-not-use-in-gae/</link>
		<comments>http://cocobear.info/blog/2009/04/25/pyfetion-can-not-use-in-gae/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 09:56:36 +0000</pubDate>
		<dc:creator>可可熊</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[编程相关]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[PyFetion]]></category>

		<guid isPermaLink="false">http://cocobear.info/blog/?p=617</guid>
		<description><![CDATA[最近有同学反映PyFetion不能在GAE上使用，我看了下别人给出的错误，问题不出在PyFetion上，无论是TCP方式还是HTTP方式，使用本机测试都可以正常工作。 应该是移动的飞信服务器屏蔽了GAE的出口IP地址（某同学反应GAE的urlopen使用的是同一IP）。 原因大概是广大GAE的爱好者众多，玩PyFetion的又比较多，所以移动不爽了，就封掉你。 问题出来了，原因也大概知道了，那怎么解决方案呢，下面就给出几个吧: 强烈要求GAE增加代理支持。 打电话给10086，然后说你的飞信上不出了，然后给客服MM说你的IP是:[GAE_IP(哪位知道这个IP来补充一下)]。 脱离GAE，使用自己的服务器。 继续使用GAE，使用另一服务器做为跳板。 解释一下，GAE不能直接访问飞信服务器了，可以在另一个地方，比如cocobear.info/PyFetion.py?phone=13838381438&#038;pwd=383838&#038;msg=^_^ 做这样的一个的接口，然后使用GAE去访问这个服务器。 Update(09.4.27): 据gohsy同学反映，GAE上不能使用是因为服务器返回了405错误，而别的fetion实现会忽略405错误，继续进行，而PyFetion遇到这个错误会产生异常。记得以前调PyFetion的时候也遇到过405错误，应该是发送的数据格式不对而造成的，所以我猜想这里是因为网络环境影响造成的数据不完整，从而使得飞信服务器返回405错误。因为在GAE上PyFetion还是可以偶尔发送成功的，所以出错的原因应该不是程序本身。 为了在GAE上能更好的使用，我修改了一下PyFetion，增加了遇到405错误时重试功能，默认重试5次，这样会使得发送的成功率提高很多，但是由于405的出现，重试多次会影响到发送的速度，这一点是无法避免的。更新请到google code查看:http://code.google.com/p/pytool/source/detail?r=30 其实根本的原因我想还是GAE上用PyFetion的人过多造成的:-) 为了在GAE上调PyFetion，在gohsy同学的帮助下，搭建了GAE环境，感觉还不错，做应用挺方便的，不错的东东。]]></description>
			<content:encoded><![CDATA[<p>最近<a href="http://cocobear.info/blog/2009/02/20/upgrade-pyfetion/">有同学反映</a><a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>不能在<a href="http://code.google.com/appengine/">GAE</a>上使用，我看了下别人给出的错误，问题不出在<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>上，无论是TCP方式还是HTTP方式，使用本机测试都可以正常工作。<br />
应该是移动的飞信服务器屏蔽了<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>的出口IP地址（某同学反应<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>的urlopen使用的是同一IP）。</p>
<p>原因大概是广大<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>的爱好者众多，玩<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>的又比较多，所以移动不爽了，就封掉你。</p>
<p>问题出来了，原因也大概知道了，那怎么解决方案呢，下面就给出几个吧:</p>
<ol>
<li>强烈要求<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>增加代理支持。</li>
<li>打电话给10086，然后说你的飞信上不出了，然后给客服MM说你的IP是:[GAE_IP(哪位知道这个IP来补充一下)]。</li>
<li>脱离<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>，使用自己的服务器。</li>
<li>继续使用<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>，使用另一服务器做为跳板。</li>
<p>        解释一下，<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>不能直接访问飞信服务器了，可以在另一个地方，比如cocobear.info/<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>.py?phone=13838381438&#038;pwd=383838&#038;msg=^_^<br />
       做这样的一个的接口，然后使用<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>去访问这个服务器。</p>
</ol>
<p>Update(09.4.27):<br />
据gohsy同学反映，<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>上不能使用是因为服务器返回了405错误，而别的fetion实现会忽略405错误，继续进行，而<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>遇到这个错误会产生异常。记得以前调<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>的时候也遇到过405错误，应该是发送的数据格式不对而造成的，所以我猜想这里是因为网络环境影响造成的数据不完整，从而使得飞信服务器返回405错误。因为在<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>上<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>还是可以偶尔发送成功的，所以出错的原因应该不是程序本身。</p>
<p>为了在<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>上能更好的使用，我修改了一下<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>，增加了遇到405错误时重试功能，默认重试5次，这样会使得发送的成功率提高很多，但是由于405的出现，重试多次会影响到发送的速度，这一点是无法避免的。更新请到google code查看:<a href="http://code.google.com/p/pytool/source/detail?r=30">http://code.google.com/p/pytool/source/detail?r=30</a></p>
<p>其实根本的原因我想还是<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>上用<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>的人过多造成的:-)</p>
<p>为了在<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>上调<a href="http://cocobear.info/blog/tag/pyfetion/" class="st_tag internal_tag" rel="tag" title="Posts tagged with PyFetion">PyFetion</a>，在gohsy同学的帮助下，搭建了<a href="http://cocobear.info/blog/tag/gae/" class="st_tag internal_tag" rel="tag" title="Posts tagged with gae">GAE</a>环境，感觉还不错，做应用挺方便的，不错的东东。</p>
]]></content:encoded>
			<wfw:commentRss>http://cocobear.info/blog/2009/04/25/pyfetion-can-not-use-in-gae/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
	</channel>
</rss>
