Cron 在本地主机上工作,但在部署 Appengine 时不起作用 [英] Cron works on local host but not when deployed Appengine

查看:27
本文介绍了Cron 在本地主机上工作,但在部署 Appengine 时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中有一个 cron 作业,它可以在我的本地主机上运行,​​但是当它部署到 appengine 时,它​​不再起作用.

I have a cron job in python that works on my localhost but when it is deployed to appengine, it no longer works.

  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' 回溯(最近一次调用最后):文件"/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/init.py",第 515 行,调用handler.get(*groups) 文件 "/base/data/home/apps/hoosheer/4.347697940058059704/hoosheer_main.py",第 199 行,在 get结果 = json_response['results'] KeyError: 'results'

'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'

这确实有效,直到我部署了我的第二个版本.有什么办法可以解决这个问题吗?

This did work until I deployed my second version. Is there any way I can fix this?

推荐答案

JSON 'results' 字段未返回,因为 Twitter 允许的每个 Ip 的请求已达到 最大配额 可用请求;这解释了为什么从您的国内 IP 中您没有任何问题并且您没有收到 HTTP 420 响应代码.

The JSON 'results' field is not returned because the requests per Ip that Twitter allows has reached the max quota of available requests; this explains why from your domestic IP you don't have any problem and you don't get an HTTP 420 response code.

不幸的是,Google App Engine 使用共享 IP 地址池* 用于传出 urlfetch 请求和 Twitter 搜索 API 不支持身份验证.

Unluckily Google App Engine uses a shared pool of IP addresses* for outgoing urlfetch requests and Twitter search APIs does not support authentication.

搜索 API 速率限制

对 Search API 的请求,托管在search.twitter.com,不算接近 REST API 限制.然而,所有来自 IP 地址的请求应用于搜索速率限制.未设置搜索速率限制公众劝阻不必要的搜索使用和滥用,但它是高于 REST 速率限制.我们感觉搜索率限制是对大多数人来说自由和足够应用程序并知道许多应用程序供应商已经找到了适合他们的需求.

Requests to the Search API, hosted on search.twitter.com, do not count towards the REST API limit. However, all requests coming from an IP address are applied to a Search Rate Limit. The Search Rate Limit isn't made public to discourage unnecessary search usage and abuse, but it is higher than the REST Rate Limit. 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.

这将迫使您认真考虑 Google App Engine 是否是您应用程序的正确选择.

This would force you to seriously think if Google App Engine is a correct choice for your application.

*我遇到了同样的问题 此处 但幸运的是 API 的开发人员启用了一种身份验证机制,允许来自同一 IP 的已验证请求.

*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.

这篇关于Cron 在本地主机上工作,但在部署 Appengine 时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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