1

I install Tweepy and Python-Twitter and try basic code

import twitter
api = twitter.Api(consumer_key=["X"],
                  consumer_secret=["X"],
                  access_token_key=["35X-X"],
                  access_token_secret=["X"])
print(api.VerifyCredentials())

and i tried to run:

Traceback (most recent call last):
  File "tweepy.py", line 1, in <module>
    import twitter
  File "/home/rodney/twitter.py", line 1, in <module>
    import tweepy
  File "/home/rodney/tweepy.py", line 2, in <module>
    api = twitter.Api(consumer_key=["X"],
AttributeError: module 'twitter' has no attribute 'Api'

get this error what i do:

if try code:

import twitter
import tweepy
api = twitter.Api(consumer_key=["X"],
                  consumer_secret=["X"],
                  access_token_key=["35X-X"],
                  access_token_secret=["X"])
print(api.VerifyCredentials())

error:

Traceback (most recent call last):
  File "tweepy.py", line 1, in <module>
    import tweepy
  File "/home/rodney/tweepy.py", line 2, in <module>
    import twitter
  File "/home/rodney/twitter.py", line 10, in <module>
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
AttributeError: module 'tweepy' has no attribute 'OAuthHandler'
frlan
  • 6,950
  • 3
  • 31
  • 72
CezmiChef
  • 53
  • 6

4 Answers4

1

Try this For what you want to do here is the code using tweepy import tweepy auth = tweepy.OAuthHandler(consumer_token, consumer_secret) auth.set_access_token(key, secret) resp= tweepy.API(auth) The rest is upon you whatever you want to do. For that you will need cursors, which can be found over here http://docs.tweepy.org/en/v3.5.0/cursor_tutorial.html

Sandeep Hukku
  • 399
  • 2
  • 8
  • Traceback (most recent call last): File "tweepy.py", line 1, in import tweepy File "/home/rodney/tweepy.py", line 2, in api = twitter.Api(consumer_key=["X"], NameError: name 'twitter' is not defined – CezmiChef Jan 19 '17 at 10:47
  • see the second line i am not calling twitter i am calling `tweepy.api`. – Sandeep Hukku Jan 19 '17 at 11:02
  • Here is the code to authenticate and get the tweets using tweepy – Sandeep Hukku Jan 19 '17 at 11:10
  • Traceback (most recent call last): File "tweepy.py", line 1, in import tweepy File "/home/rodney/tweepy.py", line 2, in import twitter File "/home/rodney/twitter.py", line 10, in auth = tweepy.OAuthHandler(consumer_key, consumer_secret) AttributeError: module 'tweepy' has no attribute 'OAuthHandler' – CezmiChef Jan 19 '17 at 11:29
1

Tweepy takes two steps to set up authorisation, as detailed in the documentation:

import tweepy

consumer_key = 'XX'
consumer_secret = 'XXX'
access_token = 'XXXX'
access_token_secret = 'XXXXX'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

print api.verify_credentials()

Tweepy is also distinct from python-twitter - you probably don't need both. I'd also avoid calling your file tweepy.py as this could cause confusion in imports later on.

asongtoruin
  • 9,794
  • 3
  • 36
  • 47
-1
pip install python-twitter 

Working fine on python3 and python2

Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
-1

If working on pycharm IDE try to add the tweepy library from File-->setting Link:https://www.youtube.com/watch?v=pKzfNBTRx5U