Google App Engine与其本地应用服务器的性能不同 [英] Google App Engine performs different from its local appserver

查看:104
本文介绍了Google App Engine与其本地应用服务器的性能不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下功能会从Google搜寻结果中提取网址。它在 dev_appserver (localhost)中运行良好,但是当我将它部署到Google App Engine时,它会显示一些错误信息。

Program:

  def googleSearch(关键字):
from re import findall
from urllib2 import build_opener $ b $ from urllib import quote,unquote
urlregex = r'< a [] href =/url\?q=(http://.+?)[& ]'
searchURL ='https://www.google.com/search?q='+ quote(keyword,safe ='')#https将排除缓存结果
#Google
opener = build_opener()
opener.addheaders = [('User-agent','Mozilla / 5.0')]
pagesource = opener.open(searchURL).read()
result = findall(urlregex,pagesource)
打印结果
resultlist = []
为结果中的网址:
resultlist.append(unquote(url))
resultlist = sorted( set(resultlist),key = resultlist.index)
返回结果列表

GAE错误:

 内部服务器错误

服务器有错误或无法执行所要求的操作。

Traceback(最近一次调用最后一次):
文件/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py,第1535行,在__call__
中rv = self.handle_exception(request,response,e)
文件/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/ webapp2.py,第1529行,在__call__
rv = self.router.dispatch(request,response)
文件/ base / data / home / runtimes / python27 / python27_lib / versions / third_party / webapp2 -2.5.2 / webapp2.py,第1278行,在default_dispatcher
中返回route.handler_adapter(request,response)
文件/ base / data / home / runtimes / python27 / python27_lib / versions / third_party /webapp2-2.5.2/webapp2.py,第1102行,在__call__
return handler.dispatch()
文件/ base / data / home / runtimes / python27 / python27_lib / versions / third_party / webapp2-2.5.2 / webapp2.py,第572行,发送
返回self.handle_exception(e,self.app.debug)
文件/ base / data / home /运行时/ python27 / python27_lib / versions / third_party / webapp2-2.5.2 / webapp2.py,第570行,分派
返回方法(* args,** kwargs)
文件/ base / data /home/apps/s~crawlnsearch/1.370098233684025667/main.py,第56行,获取
result = googleSearch(q)
文件/ base / data / home / apps / s〜crawlnsearch / 1.370098233684025667 / goosearch.py​​,第15行,googleSearch
pageource = opener.open(searchURL).read()
文件/ base / data / home / runtimes / python27 / python27_dist / lib / python2 .7 / urllib2.py,第410行,打开
response = meth(req,response)
文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7/ urllib2.py,第523行,在http_response
'http',请求,响应,代码,msg,hdrs)
文件/ base / data / home / runtimes / python27 / python27_dist / lib / python2 .7 / urllib2.py,第442行,错误
result = self._call_chain(* args)
文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7 /urllib2.py,第382行,in _call_chain
result = func(* args)
在http_error_302 $ b $中的文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py,第629行b返回self.parent.open(new,timeout = req.timeout)
文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py,第410行,in在http_response $ b中打开
response = meth(req,response)
文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py,第523行$ b'http',request,response,code,msg,hdrs)
文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py,第448行,in错误
在_call_chain $ b中返回self._call_chain(* args)
文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py,第382行$ b result = func(* args)
在http_error_default
中的文件/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py,第531行raise HTTPError (req.get_full_url(),代码,味精,hdrs,fp)
HTTPError:HTTP错误503:服务不可用

是否有人知道这个问题的解决方案。

解决方案

这可能是因为Google的数据存储索引尚未更新。等一会儿,它应该工作。 Google将其解释为此处


注意:在应用程序可用之前,数据存储索引可能需要一些时间才能生成。如果索引仍处于生成过程中,您将在访问应用程序时收到NeedIndexError。这对于这个例子来说是一个暂时的错误,所以稍后再尝试一下,如果一开始你会收到这个异常。



The following function will extract URLs form Google search result. It works well in dev_appserver(localhost) but when I deployed it on Google App Engine it show some Error.

Program:

def googleSearch(keyword):
    from re import findall
    from urllib2 import build_opener
    from urllib import quote, unquote
    urlregex = r'<a[ ]href="/url\?q=(http://.+?)[&]'
    searchURL = 'https://www.google.com/search?q=' + quote(keyword, safe = '') # https will exclude Cached results
    #Google
    opener = build_opener()
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    pagesource = opener.open(searchURL).read()
    result = findall(urlregex, pagesource)
    print result
    resultlist = []
    for url in result:
        resultlist.append(unquote(url))
    resultlist = sorted(set(resultlist), key=resultlist.index)
    return resultlist

GAE Error:

Internal Server Error

The server has either erred or is incapable of performing the requested operation.

Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~crawlnsearch/1.370098233684025667/main.py", line 56, in get
    result = googleSearch(q)
  File "/base/data/home/apps/s~crawlnsearch/1.370098233684025667/goosearch.py", line 15, in googleSearch
    pagesource = opener.open(searchURL).read()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 410, in open
    response = meth(req, response)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 442, in error
    result = self._call_chain(*args)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 629, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 410, in open
    response = meth(req, response)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 448, in error
    return self._call_chain(*args)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/urllib2.py", line 531, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 503: Service Unavailable

Did any one know solution for this problem.

解决方案

It's probably because Google's datastore indexes aren't updated yet. Wait a little while and it should work. Google explains it here

Note: The Datastore Indexes may take some time to generate before your application is available. You will receive a NeedIndexError when accessing your app if the indexes are still in the process of being generated. This is a transient error for the example, so try a little later if at first you receive this exception.

这篇关于Google App Engine与其本地应用服务器的性能不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆