Cron 在本地主机上运行,但在部署 Appengine 时不起作用
我在 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
这在本地工作正常,但在服务器上我收到以下错误:
“结果”回溯(最近调用 最后):文件 "/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['结果'] KeyError:'结果'
在我部署第二个版本之前,这确实有效。有什么办法可以解决这个问题吗?
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' 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
未返回 JSON
'results'
字段,因为 Twitter 允许的每个 Ip 的请求已达到 可用请求的最大配额;这解释了为什么您的国内 IP 没有任何问题,也没有收到 HTTP 420 响应代码。不幸的是,Google App Engine 使用共享 IP 地址池* 进行传出 urlfetch 请求,并Twitter 搜索 API 不支持身份验证。
这将迫使您认真思考 Google App Engine 是否是您应用程序的正确选择。
*我在这里遇到了同样的问题 但幸运的是,API 的开发人员启用了身份验证机制,允许来自同一 IP 的经过身份验证的请求。
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.Unluckily Google App Engine uses a shared pool of IP addresses* for outgoing urlfetch requests and Twitter search APIs does not support authentication.
This would force you to seriously think if Google App Engine is a correct choice for your application.
*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.