gpt4 book ai didi

python - Cron 在本地主机上工作,但在部署 App Engine 时不工作

转载 作者:行者123 更新时间:2023-11-28 16:53:02 25 4
gpt4 key购买 nike

我在 python 中有一个 cron 作业,它可以在我的本地主机上运行,​​但是当它部署到 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

这在本地工作正常,但在服务器上我收到以下错误:

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

在我部署第二个版本之前,这一直有效。有什么办法可以解决这个问题吗?

最佳答案

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

不幸的是,Google App Engine 使用共享的 IP 地址池* 用于传出的 urlfetch 请求和 Twitter search APIs不支持认证。

Search API Rate Limiting

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 是否是您应用程序的正确选择。

*我有同样的问题here但幸运的是,API 的开发人员启用了一种身份验证机制,允许来自同一 IP 的经过身份验证的请求。

关于python - Cron 在本地主机上工作,但在部署 App Engine 时不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4722315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com