【发布时间】:2014-10-26 14:49:09
【问题描述】:
我的脚本在 Google 应用引擎的本地主机上完美运行,但在部署脚本时在云 (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)
我只想通过爬取打印 url,部署后我可以在 localhost 上看到 url,但在应用引擎上看不到,这显示错误。
【问题讨论】:
-
服务器上的错误日志是什么?
-
@stark 它在错误日志中显示“elif self.exception: DeadlineExceededError”。
标签: python google-app-engine web-crawler