为什么在Google App Engine中使用Python API搜索YouTube视频速度慢并出现此警告?
我的应用程序是对YouTube数据Python API的“入门指南”的一个修改,详细信息可以在这里找到。以下是我的代码:
def initialize():
yt_service = gdata.youtube.service.YouTubeService()
# Turn on HTTPS/SSL access.
# Note: SSL is not available at this time for uploads.
yt_service.ssl = True
yt_service.developer_key = 'ACTUAL_API_KEY'
yt_service.client_id = 'CLIENT_ID'
def getTopVideo(self, searchTerm):
yt_service = gdata.youtube.service.YouTubeService()
query = gdata.youtube.service.YouTubeVideoQuery()
query.vq = searchTerm
query.orderby = 'relevance'
query.racy = 'include'
feed = yt_service.YouTubeQuery(query)
return feed.entry[0]
每当我的Google App Engine应用程序执行“getTopVideo”这段代码时,我都会收到一个警告:
WARNING {timestamp} urlfetch_stub.py:423] Stripped prohibited headers from URLFetch request: ['Host']
还有一个问题是,当我尝试发起多个请求(大约5个)时,搜索之间会有0.5到1秒的延迟。我可以通过查看上面警告的时间戳来判断这一点。
我该怎么做才能消除这个警告,并让搜索速度更快呢?
提前谢谢你。
1 个回答
1
看起来这是应用引擎中的一个安全“特性”:http://code.google.com/appengine/docs/python/urlfetch/overview.html#Request_Headers
这里是实际在第238行进行处理的代码:http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/api/urlfetch_stub.py?r=56
在这里遇到这个错误的人通过使用try/except来解决,虽然这可能不是最好的办法,但看起来应用引擎不这样做就不行:https://github.com/tweepy/tweepy/issues/91