Search code examples
pythongoogle-app-engineyoutubeyoutube-apigdata

Why does searching for YouTube videos using the Python API in Google App Engine go slowly and give me this warning?


My application is a modification of the "Getting Started Guide" for the YouTube Data Python API found here. Here is my code:

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]

Whenever the "getTopVideo" code executes inside of my Google App Engine application, I get a warning:

WARNING  {timestamp} urlfetch_stub.py:423] Stripped prohibited headers from URLFetch request: ['Host']

Another issue is that when I try to make several requests (~5), there is anywhere between a 0.5 and 1 second delay between searches. I can tell this by looking at the timestamps of the warning shown above.

What can I do to get rid of this warning and allow searches to be made more quickly?

Thanks in advance.


Solution

  • Looks like this is a security "feature" in app engine: http://code.google.com/appengine/docs/python/urlfetch/overview.html#Request_Headers

    Here's the actual code that does the stripping on line 238: http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/api/urlfetch_stub.py?r=56

    The person here that encountered this error worked around it by using try/except, which may not be the best solution, but it seems that app engine will not let through otherwise: https://github.com/tweepy/tweepy/issues/91