[英]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.