gpt4 book ai didi

python - App Engine - 难以访问 Twitter 数据 - Flask

转载 作者:太空宇宙 更新时间:2023-11-03 11:56:59 25 4
gpt4 key购买 nike

我在使用 Google App Engine 从 Twitter 搜索 API 获取数据时遇到问题。在个人开发环境中工作我没有问题。我能够得到我想要的 JSON。但是,一旦将代码部署到 App Engine,我就会遇到 HTTP 500 错误代码。

我对正在发生的事情的唯一想法是,我缺少的开发环境和实时 App Engine 环境之间存在一些根本区别和/或 Twitter 拒绝来 self 正在运行的 App Engine IP 的请求.我写了一个小的 @app.route 来绝对验证是否存在问题 - 在下面。

我很确定我没有达到速率限制,因为 Twitter 搜索 API 没有明确规定。我看到他们请求了一个用户代理,所以我一直在提供它,但我仍然收到相同的 500 错误。

我正在使用的实时版本在这里:http://1-alpha-3.rich90usa.appspot.com/twitter_test

如果您有任何关于这里出了什么问题的想法,我们将不胜感激。

Flask 的相关部分:

@app.route('/twitter_test')
def twitter_test():
twitter_geo_url = 'http://search.twitter.com/search.json?callback=?&rpp=100&geocode=29.6516344,-82.3248262,3mi'
twitter_result = urlfetch.fetch(twitter_geo_url, fetch_headers)
if twitter_result.status_code == 200:
return twitter_result.content

'fetch_headers' 之前定义为:

fetch_headers = {'User-Agent': "APPNAME-1-alpha-3"}

我的 Flask py 文件的顶部:

from flask import Flask, request, render_template, session, redirect
import oauth2 as oauth
import simplejson as json
import urlparse
import urllib
import httplib
import time

from google.appengine.api import urlfetch

最佳答案

正如 Calvin 所指出的,所有 App Engine 应用都从同一 IP 池中获取出站 HTTP 请求,因此问题几乎可以肯定是速率限制:

来自 http://dev.twitter.com/pages/rate-limiting :

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.

他们还特别指出 GAE 没有资格加入白名单:

An application must have a static IP to be eligible for whitelisting. This means the majority of cloud platforms, including Google App Engine, cannot be whitelisted.

Twitter 绕过速率限制的建议是切换到 the Streaming API .

关于python - App Engine - 难以访问 Twitter 数据 - Flask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5819265/

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