0

I am quite new to the concept of ipython and twython .However i want to retrieve some data using twitter.search query .But when i use it it gives me the following error

In [3]: search_results = twitter.search(q="#india", rpp="50")
---------------------------------------------------------------------------


TwythonError                              Traceback (most recent call last)
/home/vishal/<ipython-input-3-241f789b11cc> in <module>()
----> 1 search_results = twitter.search(q="#india", rpp="50")

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in search(self, **kwargs)
    365         """
    366 
--> 367         return self.get('https://api.twitter.com/1.1/search/tweets.json', params=kwargs)
    368 
    369     def searchGen(self, search_query, **kwargs):

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in get(self, endpoint, params, version)
    236 
    237     def get(self, endpoint, params=None, version='1.1'):
--> 238         return self.request(endpoint, params=params, version=version)
    239 
    240     def post(self, endpoint, params=None, files=None, version='1.1'):

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in request(self, endpoint, method, params, files, version)
    231             url = '%s/%s.json' % (self.api_url % version, endpoint)
    232 
--> 233         content = self._request(url, method=method, params=params, files=files, api_call=url)
    234 
    235         return content

/usr/local/lib/python2.7/dist-packages/twython-2.5.5-py2.7.egg/twython/twython.pyc in _request(self, url, method, params, files, api_call)
    208             raise exceptionType(error_msg,
    209                                 error_code=response.status_code,
--> 210                                 retry_after=response.headers.get('retry-after'))
    211 
    212         # if we have a json error here, then it's not an official TwitterAPI error


TwythonError: 'Bad Request: The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting. -- An error occurred processing your request

what could be the issue. Does it requires authentication

Thanks

Uselesssss
  • 2,127
  • 6
  • 28
  • 37

2 Answers2

2

Twitter API v1 search didn't not need authentication, however; the Twitter search API now requires authentication in v1.1. (https://dev.twitter.com/docs/api/1.1/get/search/tweets)

Thanks for using Twython!

Mike Helmick
  • 313
  • 1
  • 5
0

For me this code works:

from twython import Twython

twitter = Twython()
search_results = twitter.search(q="#india", rpp="50")
for tweet in search_results["results"]:
    print "Tweet from@%s Date: %s" % (tweet['from_user'].encode('utf-8'),tweet['created_at'])
    print tweet['text'].encode('utf-8'),"\n"
doru
  • 9,022
  • 2
  • 33
  • 43