![](/img/trans.png)
[英]500 Server Error in my Django App in App Engine (Google Cloud)
[英]Why 500 Server Error in google app engine after deploy?
我的腳本可以在Google App Engine的localhost上完美運行,但是在部署腳本時會在雲(appspot.com)上顯示以下錯誤:
“錯誤:服務器錯誤
服務器遇到錯誤,無法完成您的請求。
請在30秒后重試。”
這是我的代碼:
import webapp2
import sys
sys.path.insert(0, 'libs')
import requests
from bs4 import *
import re
import smtplib
from google.appengine.api import urlfetch
from google.appengine import runtime
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write("hello")
#urlfetch.set_default_fetch_deadline(60)
def spider():
count = 1
href = 'www.example.com'
while count <= 2:
new_url = href
new_source_code = urlfetch.fetch(new_url, deadline=60)
new_plain_text = new_source_code.content
new_soup = BeautifulSoup(new_plain_text)
for new_link in new_soup.find_all('table'):
for new_link1 in new_link.find_all('a'):
new_href = 'www.example.com' + new_link1.get('href')
new1_url = new_href
new1_source_code = urlfetch.fetch(new1_url, deadline=60)
new1_plain_text = new1_source_code.content
new1_soup = BeautifulSoup(new1_plain_text)
for new1_link in new1_soup.find_all('tbody'):
for new1_link1 in new1_link.find_all('a', attrs={'class': 'title'}):
new1_title = new1_link1.string
new1_title = new1_title.strip()
new1_href = 'www.example.com' + new1_link1.get('href')
self.response.write(new1_title)
self.response.write(new1_href)
count = count + 1
spider()
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
我只想通過爬網打印該網址,在部署后我可以在localhost上看到該網址,但在應用程序引擎上卻看不到,這向我顯示了錯誤。
對於自動縮放的App Engine模塊,截止日期為60秒。 在示例代碼中,您有兩個URL Fetch請求,每個請求都在一個循環中,每個請求的最后期限為60s。 假設您沒有在基本伸縮或手動伸縮實例上運行,則可能會發現60秒后看到此異常。 甚至遠程主機上的一個超時也會導致您超過前端截止期限。
該頁面將為您提供不同實例擴展類型的截止日期。
但是,您可能希望使用任務隊列將工作分解為可管理的“可重試”塊。
Google App Engine中的每個請求的最大硬性限制為60秒,因此,如果超過此限制,您將收到DeadlineExceededError
。
如果您知道要求的前期工作將花費更多時間,那么您將不得不使用Tasks API ,在其中最多可以運行10分鍾。 最后,如果您想要更長的時間,請查看Backends API ,您最多可以在24小時內運行它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.