How To Fix Tweepy AttributeError API object has no attribute search

Make sure you have latest version of tweepy installed.

In [7]:
pip install tweepy

Let us check the version of tweepy installed.

In [8]:
pip show tweepy
Name: tweepy
Version: 4.10.1
Summary: Twitter library for Python
Author: Joshua Roesslein
Author-email: [email protected]
License: MIT
Location: /home/anaconda3/lib/python3.9/site-packages
Requires: requests-oauthlib, oauthlib, requests
Note: you may need to restart the kernel to use updated packages.

Let us see if we can use tweepy now.

In [3]:
import tweepy
In [5]:
auth = tweepy.OAuth1UserHandler(
   consumer_key, consumer_secret, access_token, access_token_secret

api = tweepy.API(auth)

public_tweets = api.home_timeline()
for tweet in public_tweets:
“RIP to another pandemic perk for junior bankers,” one junior Goldman banker lamented. “I’m sure the partners still…

Ok so far so good, Let us try the method now.

In [6]:
for tweets in"aapl", lang="en"):
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_6135/ in <module>
----> 1 for tweets in"aapl", lang="en"):
      2     print(tweets)

AttributeError: 'API' object has no attribute 'search'

In tweepy 4.0.0 and above versions, has been replaced with api.search_tweets()

In [11]:
tweets = api.search_tweets(q="aapl", lang="en")
In [17]: