在 GAE 中不能使用 Python Standard Library 的任何有用到 Socket 的模組
像是 urllib、httplib 等都是被禁止的
因此若有需要存取其他網頁,則必須使用 GAE 提供的 urlfetch
範例:
from google.appengine.api import urlfetch
r = urlfetch.fetch('http://www.google.com/', method="GET")
if r.status_code == 200:
print result.content
在 GAE 的 urlfetch 介紹頁提到
urlfetch 僅能對 port 80 (http) 和 port 443 (https) 進行存取
timeout 也不能設定
而 Http Redirect 也以最大五次為限
而在實際的測試中,也發現 urlfetch 似乎有內定的 cooldown
不能在短時間內發出大量 urlfetch,否則會出現 DownloadError Exception
這對某些類型的網站並不是很方便 :(
不知道付費版本會不會有這些限制 :P
參考資料:Urlfetch Overview
2008年6月16日星期一
訂閱:
張貼意見 (Atom)
0 意見:
張貼意見