Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22852

John Ludhi/nbshare.io: Tweepy AttributeError API object has no attribute search

$
0
0

How To Fix Tweepy AttributeError API object has no attribute search

Make sure you have latest version of tweepy installed.

In [7]:
pipinstalltweepy

Let us check the version of tweepy installed.

In [8]:
pipshowtweepy
Name: tweepy
Version: 4.10.1
Summary: Twitter library for Python
Home-page: https://www.tweepy.org/
Author: Joshua Roesslein
Author-email: tweepy@googlegroups.com
License: MIT
Location: /home/anaconda3/lib/python3.9/site-packages
Requires: requests-oauthlib, oauthlib, requests
Required-by: 
Note: you may need to restart the kernel to use updated packages.

Let us see if we can use tweepy now.

In [3]:
importtweepy
In [5]:
auth=tweepy.OAuth1UserHandler(consumer_key,consumer_secret,access_token,access_token_secret)api=tweepy.API(auth)public_tweets=api.home_timeline()fortweetinpublic_tweets:print(tweet.text)break
“RIP to another pandemic perk for junior bankers,” one junior Goldman banker lamented. “I’m sure the partners still… https://t.co/Xun47Y7ovb

Ok so far so good, Let us try the api.search() method now.

In [6]:
fortweetsinapi.search(q="aapl",lang="en"):print(tweets)
---------------------------------------------------------------------------AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_6135/3050917875.py in <module>----> 1for tweets in api.search(q="aapl", lang="en"):      2     print(tweets)AttributeError: 'API' object has no attribute 'search'

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

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

Viewing all articles
Browse latest Browse all 22852

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>