简体   繁体   English

Cron在本地主机上工作,但在部署Appengine时不工作

[英]Cron works on local host but not when deployed Appengine

I have a cron job in python that works on my localhost but when it is deployed to appengine, it no longer works. 我在python中有一个cron作业,可以在我的localhost上运行,但是当它部署到appengine时,它不再有效。

  pl = db.Query(Venue).order("id")
    list = pl.fetch(limit=0)
    for p in pl:
        base_url = 'http://search.twitter.com/search.json?rpp=100&q=4sq.com/'
        query = p.twitter_ID
        url_string = base_url + query
        json_text = fetch(url_string)
        json_response = simplejson.loads(json_text.content) 
        result = json_response['results']
        for f in result:
            user = f['from_user'] 
            print user   

This works fine locally but on the server I get the following error: 这在本地工作正常但在服务器上我收到以下错误:

'results' Traceback (most recent call last): File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/ init .py", line 515, in call handler.get(*groups) File "/base/data/home/apps/hoosheer/4.347697940058059704/hoosheer_main.py", line 199, in get result = json_response['results'] KeyError: 'results' '结果'Traceback(最近一次调用最后一次):文件“/ base / python_runtime / python_lib / versions / 1 / google / appengine / ext / webapp / init .py”,第515行,在call handler.get(* groups)文件中“/base/data/home/apps/hoosheer/4.347697940058059704/hoosheer_main.py”,第199行,in get result = json_response ['results'] KeyError:'results'

This did work until I deployed my second version. 在我部署第二个版本之前,这确实有效。 Is there any way I can fix this? 有什么办法可以解决这个问题吗?

The JSON 'results' field is not returned because the requests per Ip that Twitter allows has reached the max quota of available requests; 不返回JSON 'results'字段,因为Twitter允许的每Ip请求已达到可用请求的最大配额 ; this explains why from your domestic IP you don't have any problem and you don't get an HTTP 420 response code. 这解释了为什么从你的国内IP你没有任何问题,你没有得到HTTP 420响应代码。

Unluckily Google App Engine uses a shared pool of IP addresses * for outgoing urlfetch requests and Twitter search APIs does not support authentication. 不幸的是,Google App Engine使用共享的IP地址池*来处理传出的urlfetch请求,而Twitter搜索API不支持身份验证。

Search API Rate Limiting 搜索API速率限制

Requests to the Search API, hosted on search.twitter.com, do not count towards the REST API limit. 对search.twitter.com上托管的Search API的请求不计入REST API限制。 However, all requests coming from an IP address are applied to a Search Rate Limit. 但是,来自IP地址的所有请求都将应用于搜索速率限制。 The Search Rate Limit isn't made public to discourage unnecessary search usage and abuse, but it is higher than the REST Rate Limit. 搜索速率限制不会公开,以阻止不必要的搜索使用和滥用,但它高于REST速率限制。 We feel the Search Rate Limit is both liberal and sufficient for most applications and know that many application vendors have found it suitable for their needs. 我们认为搜索速率限制对于大多数应用程序来说既自由又充足,并且知道许多应用程序供应商已经发现它适合他们的需求。

This would force you to seriously think if Google App Engine is a correct choice for your application. 这会迫使您认真思考Google App Engine是否适合您的应用程序。

*I had the same problem here but luckily the API's developer has enabled an authentication mechanism that allows authenticated requests from the same IP. *我在这里遇到了同样的问题但幸运的是,API的开发人员启用了一种身份验证机制,允许来自同一IP的经过身份验证的请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 smtplib 发送邮件在本地部署时有效,但在群中部署时失败(无法分配请求的地址) - Send mail with smtplib works when deployed in local but fails when deployed in swarm (Cannot assign requested address) appengine 使用数据存储设置本地主机以进行测试 - appengine set up local host with datastore for testing 当localhost正常工作和MacOSX时,可以通过本地IP地址访问AppEngine SDK站点 - Can access AppEngine SDK sites via local ip-address when localhost works just fine and a MacOSX 应用程序可在本地主机上运行,​​但不能在appspot上运行 - App works on Local host but not on appspot Django Web App Code可在本地开发机上运行,​​但在部署到服务器时无法运行 - Django Web App Code works on local dev machine but not when deployed to server 在 Gcloud 上部署时获取 Flask 开发服务器的服务器错误,但由于许可,作为本地服务器工作正常 - Obtain server error for Flask development server when deployed on Gcloud but works fine as local server due to permission TemplateNotFound:将网站部署在Google App Engine上但在本地主机中运行时网站运行正常时,templates / HomePage.html错误 - TemplateNotFound: templates/HomePage.html error when website is deployed on Google app engine but the website run fine when ran in local host Cron作业未与AppEngine一起运行 - Cron job not running with appengine Python:ValueError仅在AppEngine上发生,但在本地工作正常 - Python: ValueError only happening on AppEngine but works fine local Heroku 在本地工作但在部署时崩溃 - Flask - Heroku works locally but crashes when deployed - Flask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM