Error: Server Error
The server encountered an error and could not complete your request.Please try again in 30 seconds.
事實上過了 30 秒再連線也是無濟於事, 因為這是我的 Python 程式有問題之故. 到 "Logs" 檢視 Error 原因, 發現是抓取信用額度總量管制餘額表的程式 fetch_twse_daily_debit.php 時出現錯誤 :
Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject obj = __import__(path[0]) File "/base/data/home/apps/s~appfog-twstockbot/1.384633447891051628/main.py", line 228, in原來我在 webapp2.WSGIApplication 中指派了 fetch_twse_daily_debit 這個 URL 所對應的 Class 名稱, 但是卻沒有定義這個類別的內容 :('/fetch_twse_daily_debit', fetch_twse_daily_debit), NameError: name 'fetch_twse_daily_debit' is not defined
('/fetch_twse_daily_institutes', fetch_twse_daily_institutes),
('/technical_analysis', technical_analysis),
('/create_daily_report', create_daily_report),
('/fetch_daily_report', fetch_daily_report),
('/fetch_twse_daily_debit', fetch_twse_daily_debit),
所以只要補定義此類別即可 :
class fetch_twse_daily_debit(webapp2.RequestHandler):
def get(self):
url="http://mystockbot.com/cron/fetch_twse_daily_debit.php"
result=urlfetch.fetch(url, deadline=60)
if result.status_code == 200:
self.response.write(result.content)
else:
out="urlfetch failed"
self.response.write(out)
這樣 GAE 就可正常運作了, 如下圖所示, 在 cron 啟動後的三個多小時因為程式錯誤導致所有 Request 都收到 500 Server Error 回應 (紅色), 改正後全部恢復正常的藍色了 :
先跑一個星期再來看看還要改哪裡.
沒有留言 :
張貼留言