Question

I am getting the following error while I am using the following code to scrape twitter for tweets:

import scraperwiki
import simplejson
import urllib2

# Change QUERY to your search term of choice. 
# Examples: 'newsnight', 'from:bbcnewsnight', 'to:bbcnewsnight'
QUERY = '#opendata'
RESULTS_PER_PAGE = '100'
LANGUAGE = 'en'
NUM_PAGES = 1000 

for page in range(1, NUM_PAGES+1):
    base_url = 'http://search.twitter.com/search.json?q=%s&rpp=%s&lang=%s&page=%s' \
     % (urllib2.quote(QUERY), RESULTS_PER_PAGE, LANGUAGE, page)
    try:
    results_json = simplejson.loads(scraperwiki.scrape(base_url))
    for result in results_json['results']:
        #print result
        data = {}
        data['id'] = result['id']
        data['text'] = result['text']
        data['from_user'] = result['from_user']
        data['created_at'] = result['created_at']
        print data['from_user'], data['text']
        scraperwiki.sqlite.save(["id"], data) 
   except:
    print 'Oh dear, failed to scrape %s' % base_url
    break

Failed:420 Client Error (420) response time: 479 ms, http://search.twitter.com/search.json?q=opendata&rpp=100&lang=en&page=1

Please help. The same code seems to work with someone else's scraper with the same code here

Was it helpful?

Solution

Twitter's version 1 Search and Trends APIs gives the error code 420 to tell you to "Enhance your calm", when you are being rate limited. See here for more information

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top